Coverage Report

Created: 2025-09-05 06:11

/rust/registry/src/index.crates.io-6f17d22bba15001f/time-0.3.43/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
    #[inline]
11
139k
    fn parse_bytes(&self) -> Option<T> {
12
139k
        T::parse_bytes(self)
13
139k
    }
<[u8] as time::parsing::shim::IntegerParseBytes<core::num::nonzero::NonZero<u8>>>::parse_bytes
Line
Count
Source
11
16.0k
    fn parse_bytes(&self) -> Option<T> {
12
16.0k
        T::parse_bytes(self)
13
16.0k
    }
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
107k
    fn parse_bytes(&self) -> Option<T> {
12
107k
        T::parse_bytes(self)
13
107k
    }
<[u8] as time::parsing::shim::IntegerParseBytes<u32>>::parse_bytes
Line
Count
Source
11
16.0k
    fn parse_bytes(&self) -> Option<T> {
12
16.0k
        T::parse_bytes(self)
13
16.0k
    }
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
123k
            fn parse_bytes(src: &[u8]) -> Option<Self> {
29
280k
                src.iter().try_fold::<Self, _, _>(0, |result, c| {
30
280k
                    result.checked_mul(10)?.checked_add((c - b'0') as Self)
31
280k
                })
<u8 as time::parsing::shim::Integer>::parse_bytes::{closure#0}
Line
Count
Source
29
215k
                src.iter().try_fold::<Self, _, _>(0, |result, c| {
30
215k
                    result.checked_mul(10)?.checked_add((c - b'0') as Self)
31
215k
                })
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
64.2k
                src.iter().try_fold::<Self, _, _>(0, |result, c| {
30
64.2k
                    result.checked_mul(10)?.checked_add((c - b'0') as Self)
31
64.2k
                })
Unexecuted instantiation: <u128 as time::parsing::shim::Integer>::parse_bytes::{closure#0}
32
123k
            }
<u8 as time::parsing::shim::Integer>::parse_bytes
Line
Count
Source
28
107k
            fn parse_bytes(src: &[u8]) -> Option<Self> {
29
107k
                src.iter().try_fold::<Self, _, _>(0, |result, c| {
30
                    result.checked_mul(10)?.checked_add((c - b'0') as Self)
31
107k
                })
32
107k
            }
Unexecuted instantiation: <u16 as time::parsing::shim::Integer>::parse_bytes
<u32 as time::parsing::shim::Integer>::parse_bytes
Line
Count
Source
28
16.0k
            fn parse_bytes(src: &[u8]) -> Option<Self> {
29
16.0k
                src.iter().try_fold::<Self, _, _>(0, |result, c| {
30
                    result.checked_mul(10)?.checked_add((c - b'0') as Self)
31
16.0k
                })
32
16.0k
            }
Unexecuted instantiation: <u128 as time::parsing::shim::Integer>::parse_bytes
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
16.0k
            fn parse_bytes(src: &[u8]) -> Option<Self> {
44
16.0k
                Self::new(src.parse_bytes()?)
45
16.0k
            }
<core::num::nonzero::NonZero<u8> as time::parsing::shim::Integer>::parse_bytes
Line
Count
Source
43
16.0k
            fn parse_bytes(src: &[u8]) -> Option<Self> {
44
16.0k
                Self::new(src.parse_bytes()?)
45
16.0k
            }
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
}