• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / gpt-disk-rs / 14182859342

31 Mar 2025 10:40PM CUT coverage: 94.803%. Remained the same
14182859342

Pull #277

github

web-flow
Merge 9a5384971 into 32b4a7e87
Pull Request #277: uguid: Unconditionally use the Error trait

1441 of 1520 relevant lines covered (94.8%)

13.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.59
/gpt_disk_types/src/num.rs
1
// Copyright 2022 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
// option. This file may not be copied, modified, or distributed
7
// except according to those terms.
8

9
use core::fmt::{self, Debug, Display, Formatter, LowerHex};
10

11
#[cfg(feature = "bytemuck")]
12
use bytemuck::{Pod, Zeroable};
13

14
/// 16-bit unsigned integer stored as a little-endian.
15
#[derive(Clone, Copy, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
16
#[cfg_attr(feature = "bytemuck", derive(Pod, Zeroable))]
×
17
#[repr(transparent)]
18
pub struct U16Le(pub [u8; 2]);
19

20
impl U16Le {
21
    /// Convert to [`u16`] with the host's endianness.
22
    #[must_use]
23
    pub const fn to_u16(self) -> u16 {
15✔
24
        u16::from_le_bytes(self.0)
15✔
25
    }
15✔
26

27
    /// Create a `U16Le` from a [`u16`] with the host's endianness.
28
    #[must_use]
29
    pub const fn from_u16(v: u16) -> Self {
5✔
30
        Self(v.to_le_bytes())
5✔
31
    }
5✔
32

33
    /// Update the value to a [`u16`] with the host's endianness.
34
    pub fn set(&mut self, v: u16) {
1✔
35
        *self = Self::from_u16(v);
1✔
36
    }
1✔
37
}
38

39
impl Debug for U16Le {
40
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1✔
41
        Debug::fmt(&self.to_u16(), f)
1✔
42
    }
1✔
43
}
44

45
impl Display for U16Le {
46
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
2✔
47
        Display::fmt(&self.to_u16(), f)
2✔
48
    }
2✔
49
}
50

51
impl LowerHex for U16Le {
52
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
3✔
53
        format_u8_slice_lower_hex_le(f, &self.0)
3✔
54
    }
3✔
55
}
56

57
/// 32-bit unsigned integer stored as a little-endian.
58
#[derive(Clone, Copy, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
59
#[cfg_attr(feature = "bytemuck", derive(Pod, Zeroable))]
×
60
#[repr(transparent)]
61
pub struct U32Le(pub [u8; 4]);
62

63
impl U32Le {
64
    /// Convert to [`u32`] with the host's endianness.
65
    #[must_use]
66
    pub const fn to_u32(self) -> u32 {
75✔
67
        u32::from_le_bytes(self.0)
75✔
68
    }
75✔
69

70
    /// Create a `U32Le` from a [`u32`] with the host's endianness.
71
    #[must_use]
72
    pub const fn from_u32(v: u32) -> Self {
91✔
73
        Self(v.to_le_bytes())
91✔
74
    }
91✔
75

76
    /// Update the value to a [`u32`] with the host's endianness.
77
    pub fn set(&mut self, v: u32) {
1✔
78
        *self = Self::from_u32(v);
1✔
79
    }
1✔
80
}
81

82
impl Debug for U32Le {
83
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
18✔
84
        Debug::fmt(&self.to_u32(), f)
18✔
85
    }
18✔
86
}
87

88
impl Display for U32Le {
89
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
32✔
90
        Display::fmt(&self.to_u32(), f)
32✔
91
    }
32✔
92
}
93

94
impl LowerHex for U32Le {
95
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
15✔
96
        format_u8_slice_lower_hex_le(f, &self.0)
15✔
97
    }
15✔
98
}
99

100
/// 64-bit unsigned integer stored as a little-endian.
101
#[derive(Clone, Copy, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
102
#[cfg_attr(feature = "bytemuck", derive(Pod, Zeroable))]
×
103
#[repr(transparent)]
104
pub struct U64Le(pub [u8; 8]);
105

106
impl U64Le {
107
    /// Convert to [`u64`] with the host's endianness.
108
    #[must_use]
109
    pub const fn to_u64(self) -> u64 {
48✔
110
        u64::from_le_bytes(self.0)
48✔
111
    }
48✔
112

113
    /// Create a `U64Le` from a [`u64`] with the host's endianness.
114
    #[must_use]
115
    pub const fn from_u64(v: u64) -> Self {
105✔
116
        Self(v.to_le_bytes())
105✔
117
    }
105✔
118

119
    /// Update the value to a [`u64`] with the host's endianness.
120
    pub fn set(&mut self, v: u64) {
1✔
121
        *self = Self::from_u64(v);
1✔
122
    }
1✔
123
}
124

125
impl Debug for U64Le {
126
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
13✔
127
        Debug::fmt(&self.to_u64(), f)
13✔
128
    }
13✔
129
}
130

131
impl Display for U64Le {
132
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
2✔
133
        Display::fmt(&self.to_u64(), f)
2✔
134
    }
2✔
135
}
136

137
impl LowerHex for U64Le {
138
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
3✔
139
        format_u8_slice_lower_hex_le(f, &self.0)
3✔
140
    }
3✔
141
}
142

143
pub(crate) fn format_u8_slice_lower_hex_le(
30✔
144
    f: &mut Formatter<'_>,
30✔
145
    s: &[u8],
30✔
146
) -> fmt::Result {
30✔
147
    if f.alternate() {
30✔
148
        f.write_str("0x")?;
18✔
149
    }
12✔
150
    for byte in s.iter().rev() {
114✔
151
        write!(f, "{byte:02x}")?;
114✔
152
    }
153
    Ok(())
30✔
154
}
30✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc