Debian Codegraph @

src/btoi.rs

raw symbols SCIP
1 //! A module with utilities to turn byte slices with decimal numbers back into their
2 //! binary representation.
3 //!
4 //! ### Credits
5 //!
6 //! This module was ported from <https://github.com/niklasf/rust-btoi> version 0.4.3
7 //! see <https://github.com/GitoxideLabs/gitoxide/issues/729> for how it came to be in order
8 //! to save 2.2 seconds of per-core compile time by not compiling the `num-traits` crate
9 //! anymore.
10 //!
11 //! Licensed with compatible licenses [MIT] and [Apache]
12 //!
13 //! [MIT]: https://github.com/niklasf/rust-btoi/blob/master/LICENSE-MIT
14 //! [Apache]: https://github.com/niklasf/rust-btoi/blob/master/LICENSE-APACHE
15
16 /// An error that can occur when parsing an integer.
17 ///
18 /// * No digits
19 /// * Invalid digit
20 /// * Overflow
21 /// * Underflow
22 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
23 pub struct ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
24 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#,
25 }
26
27 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
28 enum ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind# {
29 Emptyrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Empty#,
30 InvalidDigitrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#InvalidDigit#,
31 Overflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Overflow#,
32 Underflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Underflow#,
33 }
34
35 impl ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
36 fn descrust-analyzer cargo gix-utils 0.3.5 btoi/impl#[ParseIntegerError]desc().(&self) -> &str {
37 match self.kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind. {
38 ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Emptyrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Empty# => "cannot parse integer without digits",
39 ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::InvalidDigitrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#InvalidDigit# => "invalid digit found in slice",
40 ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Overflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Overflow# => "number too large to fit in target type",
41 ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Underflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Underflow# => "number too small to fit in target type",
42 }
43 }
44 }
45
46 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
47 fn fmtrust-analyzer cargo gix-utils 0.3.5 btoi/impl#[ParseIntegerError][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
48 self.descrust-analyzer cargo gix-utils 0.3.5 btoi/impl#[ParseIntegerError]desc().().fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[str][Display]fmt().(f)
49 }
50 }
51
52 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
53 fn descriptionrust-analyzer cargo gix-utils 0.3.5 btoi/impl#[ParseIntegerError][Error]description().(&self) -> &str {
54 self.descrust-analyzer cargo gix-utils 0.3.5 btoi/impl#[ParseIntegerError]desc().()
55 }
56 }
57
58 /// Converts a byte slice to an integer. Signs are not allowed.
59 ///
60 /// # Errors
61 ///
62 /// Returns [`ParseIntegerError`] for any of the following conditions:
63 ///
64 /// * `bytes` is empty
65 /// * not all characters of `bytes` are `0-9`
66 /// * the number overflows `I`
67 ///
68 /// # Panics
69 ///
70 /// Panics in the pathological case that there is no representation of `10`
71 /// in `I`.
72 ///
73 /// # Examples
74 ///
75 /// ```
76 /// # use gix_utils::btoi::to_unsigned;
77 /// assert_eq!(Ok(12345), to_unsigned(b"12345"));
78 /// assert!(to_unsigned::<u8>(b"+1").is_err()); // only btoi allows signs
79 /// assert!(to_unsigned::<u8>(b"256").is_err()); // overflow
80 /// ```
81 #[track_caller]
82 pub fn to_unsignedrust-analyzer cargo gix-utils 0.3.5 btoi/to_unsigned().<I: MinNumTraitsrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#>(bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<I, ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#> {
83 to_unsigned_with_radixrust-analyzer cargo gix-utils 0.3.5 btoi/to_unsigned_with_radix().(bytes, 10)
84 }
85
86 /// Converts a byte slice in a given base to an integer. Signs are not allowed.
87 ///
88 /// # Errors
89 ///
90 /// Returns [`ParseIntegerError`] for any of the following conditions:
91 ///
92 /// * `bytes` is empty
93 /// * not all characters of `bytes` are `0-9`, `a-z` or `A-Z`
94 /// * not all characters refer to digits in the given `radix`
95 /// * the number overflows `I`
96 ///
97 /// # Panics
98 ///
99 /// Panics if `radix` is not in the range `2..=36` (or in the pathological
100 /// case that there is no representation of `radix` in `I`).
101 ///
102 /// # Examples
103 ///
104 /// ```
105 /// # use gix_utils::btoi::to_unsigned_with_radix;
106 /// assert_eq!(Ok(255), to_unsigned_with_radix(b"ff", 16));
107 /// assert_eq!(Ok(42), to_unsigned_with_radix(b"101010", 2));
108 /// ```
109 pub fn to_unsigned_with_radixrust-analyzer cargo gix-utils 0.3.5 btoi/to_unsigned_with_radix().<I: MinNumTraitsrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#>(bytes: &[u8], radix: u32) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<I, ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#> {
110 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
111 (2..=36).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&radix),
112 "radix must lie in the range 2..=36, found {radix}"
113 );
114
115 let base = I::from_u32rust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#from_u32().(radix).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("radix can be represented as integer");
116
117 if bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
118 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# { kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Emptyrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Empty# });
119 }
120
121 let mut result = I::ZEROrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#ZERO.;
122
123 for &digit in bytes {
124 let x = match char::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/convert/impl#[char][`From<u8>`]from().(digit).to_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_digit().(radix).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(I::from_u32rust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#from_u32().) {
125 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x,
126 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
127 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
128 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::InvalidDigitrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#InvalidDigit#,
129 });
130 }
131 };
132 result = match result.checked_mulrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_mul().(base) {
133 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) => result,
134 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
135 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
136 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Overflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Overflow#,
137 });
138 }
139 };
140 result = match result.checked_addrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_add().(x) {
141 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) => result,
142 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
143 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
144 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Overflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Overflow#,
145 });
146 }
147 };
148 }
149
150 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result)
151 }
152
153 /// Converts a byte slice to an integer.
154 ///
155 /// Like [`to_unsigned`], but numbers may optionally start with a sign (`-` or `+`).
156 ///
157 /// # Errors
158 ///
159 /// Returns [`ParseIntegerError`] for any of the following conditions:
160 ///
161 /// * `bytes` has no digits
162 /// * not all characters of `bytes` are `0-9`, excluding an optional leading
163 /// sign
164 /// * the number overflows or underflows `I`
165 ///
166 /// # Panics
167 ///
168 /// Panics in the pathological case that there is no representation of `10`
169 /// in `I`.
170 ///
171 /// # Examples
172 ///
173 /// ```
174 /// # use gix_utils::btoi::to_signed;
175 /// assert_eq!(Ok(123), to_signed(b"123"));
176 /// assert_eq!(Ok(123), to_signed(b"+123"));
177 /// assert_eq!(Ok(-123), to_signed(b"-123"));
178 ///
179 /// assert!(to_signed::<u8>(b"123456789").is_err()); // overflow
180 /// assert!(to_signed::<u8>(b"-1").is_err()); // underflow
181 ///
182 /// assert!(to_signed::<i32>(b" 42").is_err()); // leading space
183 /// ```
184 pub fn to_signedrust-analyzer cargo gix-utils 0.3.5 btoi/to_signed().<I: MinNumTraitsrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#>(bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<I, ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#> {
185 to_signed_with_radixrust-analyzer cargo gix-utils 0.3.5 btoi/to_signed_with_radix().(bytes, 10)
186 }
187
188 /// Converts a byte slice in a given base to an integer.
189 ///
190 /// Like [`to_unsigned_with_radix`], but numbers may optionally start with a sign
191 /// (`-` or `+`).
192 ///
193 /// # Errors
194 ///
195 /// Returns [`ParseIntegerError`] for any of the following conditions:
196 ///
197 /// * `bytes` has no digits
198 /// * not all characters of `bytes` are `0-9`, `a-z`, `A-Z`, excluding an
199 /// optional leading sign
200 /// * not all characters refer to digits in the given `radix`, excluding an
201 /// optional leading sign
202 /// * the number overflows or underflows `I`
203 ///
204 /// # Panics
205 ///
206 /// Panics if `radix` is not in the range `2..=36` (or in the pathological
207 /// case that there is no representation of `radix` in `I`).
208 ///
209 /// # Examples
210 ///
211 /// ```
212 /// # use gix_utils::btoi::to_signed_with_radix;
213 /// assert_eq!(Ok(10), to_signed_with_radix(b"a", 16));
214 /// assert_eq!(Ok(10), to_signed_with_radix(b"+a", 16));
215 /// assert_eq!(Ok(-42), to_signed_with_radix(b"-101010", 2));
216 /// ```
217 pub fn to_signed_with_radixrust-analyzer cargo gix-utils 0.3.5 btoi/to_signed_with_radix().<I: MinNumTraitsrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#>(bytes: &[u8], radix: u32) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<I, ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#> {
218 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
219 (2..=36).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&radix),
220 "radix must lie in the range 2..=36, found {radix}"
221 );
222
223 let base = I::from_u32rust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#from_u32().(radix).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("radix can be represented as integer");
224
225 if bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
226 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# { kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Emptyrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Empty# });
227 }
228
229 let digits = match bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). {
230 b'+' => return to_unsigned_with_radixrust-analyzer cargo gix-utils 0.3.5 btoi/to_unsigned_with_radix().(&bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., radix),
231 b'-' => &bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
232 _ => return to_unsigned_with_radixrust-analyzer cargo gix-utils 0.3.5 btoi/to_unsigned_with_radix().(bytes, radix),
233 };
234
235 if digits.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
236 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# { kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Emptyrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Empty# });
237 }
238
239 let mut result = I::ZEROrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#ZERO.;
240
241 for &digit in digits {
242 let x = match char::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/convert/impl#[char][`From<u8>`]from().(digit).to_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_digit().(radix).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(I::from_u32rust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#from_u32().) {
243 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => x,
244 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
245 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
246 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::InvalidDigitrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#InvalidDigit#,
247 });
248 }
249 };
250 result = match result.checked_mulrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_mul().(base) {
251 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) => result,
252 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
253 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
254 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Underflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Underflow#,
255 });
256 }
257 };
258 result = match result.checked_subrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_sub().(x) {
259 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) => result,
260 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
261 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntegerErrorrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError# {
262 kindrust-analyzer cargo gix-utils 0.3.5 btoi/ParseIntegerError#kind.: ErrorKindrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#::Underflowrust-analyzer cargo gix-utils 0.3.5 btoi/ErrorKind#Underflow#,
263 });
264 }
265 };
266 }
267
268 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result)
269 }
270
271 /// minimal subset of traits used by [`to_signed_with_radix`] and [`to_unsigned_with_radix`]
272 pub trait MinNumTraitsrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<u32> {
273 /// the 0 value for this type
274 const ZEROrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#ZERO.: Self;
275 /// convert from a unsigned 32-bit word
276 fn from_u32rust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#from_u32().(n: u32) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self> {
277 Self::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#try_from().(n).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
278 }
279 /// the checked multiplication operation for this type
280 fn checked_mulrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_mul().(self, rhs: Self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self>;
281 /// the chekced addition operation for this type
282 fn checked_addrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_add().(self, rhs: Self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self>;
283 /// the checked subtraction operation for this type
284 fn checked_subrust-analyzer cargo gix-utils 0.3.5 btoi/MinNumTraits#checked_sub().(self, v: Self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self>;
285 }
286
287 macro_rules! impl_checkedrust-analyzer cargo gix-utils 0.3.5 btoi/impl_checked! {
288 ($f:ident) => {
289 fn $f(self, rhs: Self) -> Option<Self> {
290 Self::$f(self, rhs)
291 }
292 };
293 }
294
295 macro_rules! min_num_traitsrust-analyzer cargo gix-utils 0.3.5 btoi/min_num_traits! {
296 ($t:ty) => {
297 impl MinNumTraits for $t {
298 const ZERO: Self = 0;
299 impl_checked!(checked_add);
300 impl_checked!(checked_mul);
301 impl_checked!(checked_sub);
302 }
303 };
304 }
305
306 min_num_traitsrust-analyzer cargo gix-utils 0.3.5 btoi/min_num_traits!!(i32);
307 min_num_traitsrust-analyzer cargo gix-utils 0.3.5 btoi/min_num_traits!!(i64);
308 min_num_traitsrust-analyzer cargo gix-utils 0.3.5 btoi/min_num_traits!!(u64);
309 min_num_traitsrust-analyzer cargo gix-utils 0.3.5 btoi/min_num_traits!!(u8);
310 min_num_traitsrust-analyzer cargo gix-utils 0.3.5 btoi/min_num_traits!!(usize);