/rust/registry/src/index.crates.io-1949cf8c6b5b557f/time-0.3.44/src/parsing/shim.rs
Line | Count | Source |
1 | | //! Extension traits for things either not implemented or not yet stable in the MSRV. |
2 | | |
3 | | /// Equivalent of `foo.parse()` for slices. |
4 | | pub(crate) trait IntegerParseBytes<T> { |
5 | | #[allow(clippy::missing_docs_in_private_items)] |
6 | | fn parse_bytes(&self) -> Option<T>; |
7 | | } |
8 | | |
9 | | impl<T: Integer> IntegerParseBytes<T> for [u8] { |
10 | | #[inline] |
11 | 197k | fn parse_bytes(&self) -> Option<T> { |
12 | 197k | T::parse_bytes(self) |
13 | 197k | } <[u8] as time::parsing::shim::IntegerParseBytes<core::num::nonzero::NonZero<u8>>>::parse_bytes Line | Count | Source | 11 | 22.5k | fn parse_bytes(&self) -> Option<T> { | 12 | 22.5k | T::parse_bytes(self) | 13 | 22.5k | } |
Unexecuted instantiation: <[u8] as time::parsing::shim::IntegerParseBytes<core::num::nonzero::NonZero<u16>>>::parse_bytes <[u8] as time::parsing::shim::IntegerParseBytes<u8>>::parse_bytes Line | Count | Source | 11 | 152k | fn parse_bytes(&self) -> Option<T> { | 12 | 152k | T::parse_bytes(self) | 13 | 152k | } |
<[u8] as time::parsing::shim::IntegerParseBytes<u32>>::parse_bytes Line | Count | Source | 11 | 22.5k | fn parse_bytes(&self) -> Option<T> { | 12 | 22.5k | T::parse_bytes(self) | 13 | 22.5k | } |
Unexecuted instantiation: <[u8] as time::parsing::shim::IntegerParseBytes<u128>>::parse_bytes Unexecuted instantiation: <[u8] as time::parsing::shim::IntegerParseBytes<u16>>::parse_bytes |
14 | | } |
15 | | |
16 | | /// Marker trait for all integer types, including `NonZero*` |
17 | | pub(crate) trait Integer: Sized { |
18 | | #[allow(clippy::missing_docs_in_private_items)] |
19 | | fn parse_bytes(src: &[u8]) -> Option<Self>; |
20 | | } |
21 | | |
22 | | /// Parse the given types from bytes. |
23 | | macro_rules! impl_parse_bytes { |
24 | | ($($t:ty)*) => ($( |
25 | | impl Integer for $t { |
26 | | #[allow(trivial_numeric_casts)] |
27 | | #[inline] |
28 | 175k | fn parse_bytes(src: &[u8]) -> Option<Self> { |
29 | 395k | src.iter().try_fold::<Self, _, _>(0, |result, c| { |
30 | 395k | result.checked_mul(10)?.checked_add((c - b'0') as Self) |
31 | 395k | }) Unexecuted instantiation: <u16 as time::parsing::shim::Integer>::parse_bytes::{closure#0} <u32 as time::parsing::shim::Integer>::parse_bytes::{closure#0} Line | Count | Source | 29 | 90.3k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 30 | 90.3k | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 31 | 90.3k | }) |
Unexecuted instantiation: <u128 as time::parsing::shim::Integer>::parse_bytes::{closure#0} <u8 as time::parsing::shim::Integer>::parse_bytes::{closure#0} Line | Count | Source | 29 | 305k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 30 | 305k | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 31 | 305k | }) |
|
32 | 175k | } Unexecuted instantiation: <u16 as time::parsing::shim::Integer>::parse_bytes <u32 as time::parsing::shim::Integer>::parse_bytes Line | Count | Source | 28 | 22.5k | fn parse_bytes(src: &[u8]) -> Option<Self> { | 29 | 22.5k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 30 | | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 31 | | }) | 32 | 22.5k | } |
Unexecuted instantiation: <u128 as time::parsing::shim::Integer>::parse_bytes <u8 as time::parsing::shim::Integer>::parse_bytes Line | Count | Source | 28 | 152k | fn parse_bytes(src: &[u8]) -> Option<Self> { | 29 | 152k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 30 | | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 31 | | }) | 32 | 152k | } |
|
33 | | } |
34 | | )*) |
35 | | } |
36 | | impl_parse_bytes! { u8 u16 u32 u128 } |
37 | | |
38 | | /// Parse the given types from bytes. |
39 | | macro_rules! impl_parse_bytes_nonzero { |
40 | | ($($t:ty)*) => {$( |
41 | | impl Integer for $t { |
42 | | #[inline] |
43 | 22.5k | fn parse_bytes(src: &[u8]) -> Option<Self> { |
44 | 22.5k | Self::new(src.parse_bytes()?) |
45 | 22.5k | } <core::num::nonzero::NonZero<u8> as time::parsing::shim::Integer>::parse_bytes Line | Count | Source | 43 | 22.5k | fn parse_bytes(src: &[u8]) -> Option<Self> { | 44 | 22.5k | Self::new(src.parse_bytes()?) | 45 | 22.5k | } |
Unexecuted instantiation: <core::num::nonzero::NonZero<u16> as time::parsing::shim::Integer>::parse_bytes |
46 | | } |
47 | | )*} |
48 | | } |
49 | | |
50 | | impl_parse_bytes_nonzero! { |
51 | | core::num::NonZero<u8> |
52 | | core::num::NonZero<u16> |
53 | | } |