Coverage Report

Created: 2026-01-16 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/asn1-rs-0.7.1/src/tostatic.rs
Line
Count
Source
1
use alloc::borrow::Cow;
2
use alloc::string::ToString;
3
4
/// Common trait for objects that can be transformed to a `'static` version of `self`
5
pub trait ToStatic {
6
    type Owned: 'static;
7
    fn to_static(&self) -> Self::Owned;
8
}
9
10
impl ToStatic for Cow<'_, str> {
11
    type Owned = Cow<'static, str>;
12
406k
    fn to_static(&self) -> <Self as ToStatic>::Owned {
13
406k
        Cow::Owned(self.to_string())
14
406k
    }
15
}
16
17
impl ToStatic for Cow<'_, [u8]> {
18
    type Owned = Cow<'static, [u8]>;
19
14.5k
    fn to_static(&self) -> <Self as ToStatic>::Owned {
20
14.5k
        Cow::Owned(self.to_vec())
21
14.5k
    }
22
}
23
24
macro_rules! impl_tostatic_primitive {
25
    ($t:ty) => {
26
        impl ToStatic for $t {
27
            type Owned = $t;
28
1.01M
            fn to_static(&self) -> <Self as ToStatic>::Owned {
29
1.01M
                self.clone()
30
1.01M
            }
<u8 as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
28
1.24k
            fn to_static(&self) -> <Self as ToStatic>::Owned {
29
1.24k
                self.clone()
30
1.24k
            }
<u32 as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
28
1.00M
            fn to_static(&self) -> <Self as ToStatic>::Owned {
29
1.00M
                self.clone()
30
1.00M
            }
<bool as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
28
7.38k
            fn to_static(&self) -> <Self as ToStatic>::Owned {
29
7.38k
                self.clone()
30
7.38k
            }
Unexecuted instantiation: <alloc::string::String as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <i8 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <i16 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <i32 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <i64 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <i128 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <isize as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <u16 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <u64 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <u128 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <usize as asn1_rs::tostatic::ToStatic>::to_static
31
        }
32
    };
33
    ($t:ty => $to:ty, $closure:expr) => {
34
        impl ToStatic for $t {
35
            type Owned = $to;
36
0
            fn to_static(&self) -> <Self as ToStatic>::Owned {
37
0
                let f: &dyn Fn(&Self) -> $to = &$closure;
38
0
                f(self)
39
0
            }
40
        }
41
    };
42
    (I $($types: ty)+) => {
43
        $(
44
            impl_tostatic_primitive!($types);
45
        )*
46
    };
47
}
48
49
impl_tostatic_primitive!(bool);
50
impl_tostatic_primitive!(I i8 i16 i32 i64 i128 isize);
51
impl_tostatic_primitive!(I u8 u16 u32 u64 u128 usize);
52
53
impl<T> ToStatic for &'_ T
54
where
55
    T: ToStatic,
56
{
57
    type Owned = T::Owned;
58
59
0
    fn to_static(&self) -> Self::Owned {
60
0
        (*self).to_static()
61
0
    }
62
}
63
64
impl<T> ToStatic for Option<T>
65
where
66
    T: ToStatic,
67
{
68
    type Owned = Option<T::Owned>;
69
70
1.00M
    fn to_static(&self) -> Self::Owned {
71
1.00M
        self.as_ref().map(ToStatic::to_static)
72
1.00M
    }
<core::option::Option<alloc::vec::Vec<ldap_parser::ldap::Control>> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
977k
    fn to_static(&self) -> Self::Owned {
71
977k
        self.as_ref().map(ToStatic::to_static)
72
977k
    }
<core::option::Option<alloc::borrow::Cow<[u8]>> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
16.6k
    fn to_static(&self) -> Self::Owned {
71
16.6k
        self.as_ref().map(ToStatic::to_static)
72
16.6k
    }
<core::option::Option<ldap_parser::ldap::LdapDN> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
697
    fn to_static(&self) -> Self::Owned {
71
697
        self.as_ref().map(ToStatic::to_static)
72
697
    }
<core::option::Option<ldap_parser::ldap::LdapOID> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
7.04k
    fn to_static(&self) -> Self::Owned {
71
7.04k
        self.as_ref().map(ToStatic::to_static)
72
7.04k
    }
<core::option::Option<ldap_parser::ldap::LdapString> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
1.41k
    fn to_static(&self) -> Self::Owned {
71
1.41k
        self.as_ref().map(ToStatic::to_static)
72
1.41k
    }
<core::option::Option<ldap_parser::filter::AttributeDescription> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
1.41k
    fn to_static(&self) -> Self::Owned {
71
1.41k
        self.as_ref().map(ToStatic::to_static)
72
1.41k
    }
<core::option::Option<bool> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
70
1.41k
    fn to_static(&self) -> Self::Owned {
71
1.41k
        self.as_ref().map(ToStatic::to_static)
72
1.41k
    }
Unexecuted instantiation: <core::option::Option<_> as asn1_rs::tostatic::ToStatic>::to_static
73
}
74
75
#[cfg(feature = "std")]
76
const _: () = {
77
    impl_tostatic_primitive!(I String);
78
0
    impl_tostatic_primitive!(str => String, |s| s.to_string());
79
80
    impl<T> ToStatic for Box<T>
81
    where
82
        T: ToStatic,
83
    {
84
        type Owned = Box<T::Owned>;
85
86
273
        fn to_static(&self) -> Self::Owned {
87
273
            Box::new(self.as_ref().to_static())
88
273
        }
<alloc::boxed::Box<ldap_parser::filter::Filter> as asn1_rs::tostatic::ToStatic>::to_static
Line
Count
Source
86
273
        fn to_static(&self) -> Self::Owned {
87
273
            Box::new(self.as_ref().to_static())
88
273
        }
Unexecuted instantiation: <alloc::boxed::Box<_> as asn1_rs::tostatic::ToStatic>::to_static
89
    }
90
};