Coverage Report

Created: 2025-12-28 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/asn1-rs-0.7.0/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
0
    fn to_static(&self) -> <Self as ToStatic>::Owned {
13
0
        Cow::Owned(self.to_string())
14
0
    }
15
}
16
17
impl ToStatic for Cow<'_, [u8]> {
18
    type Owned = Cow<'static, [u8]>;
19
0
    fn to_static(&self) -> <Self as ToStatic>::Owned {
20
0
        Cow::Owned(self.to_vec())
21
0
    }
22
}
23
24
macro_rules! impl_tostatic_primitive {
25
    ($t:ty) => {
26
        impl ToStatic for $t {
27
            type Owned = $t;
28
0
            fn to_static(&self) -> <Self as ToStatic>::Owned {
29
0
                self.clone()
30
0
            }
Unexecuted instantiation: <bool 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: <u8 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <u16 as asn1_rs::tostatic::ToStatic>::to_static
Unexecuted instantiation: <u32 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
Unexecuted instantiation: <alloc::string::String 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
0
    fn to_static(&self) -> Self::Owned {
71
0
        self.as_ref().map(ToStatic::to_static)
72
0
    }
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
0
        fn to_static(&self) -> Self::Owned {
87
0
            Box::new(self.as_ref().to_static())
88
0
        }
89
    }
90
};