/rust/registry/src/index.crates.io-6f17d22bba15001f/time-0.3.41/src/parsing/shim.rs
Line | Count | Source (jump to first uncovered line) |
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 | 131k | fn parse_bytes(&self) -> Option<T> { |
11 | 131k | T::parse_bytes(self) |
12 | 131k | } <[u8] as time::parsing::shim::IntegerParseBytes<core::num::nonzero::NonZero<u8>>>::parse_bytes Line | Count | Source | 10 | 15.1k | fn parse_bytes(&self) -> Option<T> { | 11 | 15.1k | T::parse_bytes(self) | 12 | 15.1k | } |
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 | 10 | 101k | fn parse_bytes(&self) -> Option<T> { | 11 | 101k | T::parse_bytes(self) | 12 | 101k | } |
<[u8] as time::parsing::shim::IntegerParseBytes<u32>>::parse_bytes Line | Count | Source | 10 | 15.1k | fn parse_bytes(&self) -> Option<T> { | 11 | 15.1k | T::parse_bytes(self) | 12 | 15.1k | } |
Unexecuted instantiation: <[u8] as time::parsing::shim::IntegerParseBytes<u128>>::parse_bytes Unexecuted instantiation: <[u8] as time::parsing::shim::IntegerParseBytes<u16>>::parse_bytes |
13 | | } |
14 | | |
15 | | /// Marker trait for all integer types, including `NonZero*` |
16 | | pub(crate) trait Integer: Sized { |
17 | | #[allow(clippy::missing_docs_in_private_items)] |
18 | | fn parse_bytes(src: &[u8]) -> Option<Self>; |
19 | | } |
20 | | |
21 | | /// Parse the given types from bytes. |
22 | | macro_rules! impl_parse_bytes { |
23 | | ($($t:ty)*) => ($( |
24 | | impl Integer for $t { |
25 | | #[allow(trivial_numeric_casts)] |
26 | 116k | fn parse_bytes(src: &[u8]) -> Option<Self> { |
27 | 263k | src.iter().try_fold::<Self, _, _>(0, |result, c| { |
28 | 263k | result.checked_mul(10)?.checked_add((c - b'0') as Self) |
29 | 263k | }) <u8 as time::parsing::shim::Integer>::parse_bytes::{closure#0} Line | Count | Source | 27 | 202k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 28 | 202k | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 29 | 202k | }) |
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 | 27 | 60.7k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 28 | 60.7k | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 29 | 60.7k | }) |
Unexecuted instantiation: <u128 as time::parsing::shim::Integer>::parse_bytes::{closure#0} |
30 | 116k | } <u8 as time::parsing::shim::Integer>::parse_bytes Line | Count | Source | 26 | 101k | fn parse_bytes(src: &[u8]) -> Option<Self> { | 27 | 101k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 28 | | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 29 | 101k | }) | 30 | 101k | } |
Unexecuted instantiation: <u16 as time::parsing::shim::Integer>::parse_bytes <u32 as time::parsing::shim::Integer>::parse_bytes Line | Count | Source | 26 | 15.1k | fn parse_bytes(src: &[u8]) -> Option<Self> { | 27 | 15.1k | src.iter().try_fold::<Self, _, _>(0, |result, c| { | 28 | | result.checked_mul(10)?.checked_add((c - b'0') as Self) | 29 | 15.1k | }) | 30 | 15.1k | } |
Unexecuted instantiation: <u128 as time::parsing::shim::Integer>::parse_bytes |
31 | | } |
32 | | )*) |
33 | | } |
34 | | impl_parse_bytes! { u8 u16 u32 u128 } |
35 | | |
36 | | /// Parse the given types from bytes. |
37 | | macro_rules! impl_parse_bytes_nonzero { |
38 | | ($($t:ty)*) => {$( |
39 | | impl Integer for $t { |
40 | 15.1k | fn parse_bytes(src: &[u8]) -> Option<Self> { |
41 | 15.1k | Self::new(src.parse_bytes()?) |
42 | 15.1k | } <core::num::nonzero::NonZero<u8> as time::parsing::shim::Integer>::parse_bytes Line | Count | Source | 40 | 15.1k | fn parse_bytes(src: &[u8]) -> Option<Self> { | 41 | 15.1k | Self::new(src.parse_bytes()?) | 42 | 15.1k | } |
Unexecuted instantiation: <core::num::nonzero::NonZero<u16> as time::parsing::shim::Integer>::parse_bytes |
43 | | } |
44 | | )*} |
45 | | } |
46 | | |
47 | | impl_parse_bytes_nonzero! { |
48 | | core::num::NonZeroU8 |
49 | | core::num::NonZeroU16 |
50 | | } |