Coverage Report

Created: 2024-10-16 07:58

/rust/registry/src/index.crates.io-6f17d22bba15001f/rkyv-0.7.44/src/with/atomic.rs
Line
Count
Source (jump to first uncovered line)
1
use crate::{
2
    with::{ArchiveWith, Atomic, DeserializeWith, SerializeWith, With},
3
    Archived, Fallible,
4
};
5
use core::sync::atomic::{
6
    AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicU16, AtomicU32, AtomicU8, Ordering,
7
};
8
#[cfg(has_atomics_64)]
9
use core::sync::atomic::{AtomicI64, AtomicU64};
10
11
macro_rules! impl_atomic {
12
    (@serialize_deserialize $type:ty) => {
13
        impl<S: Fallible + ?Sized> SerializeWith<$type, S> for Atomic {
14
            #[inline]
15
0
            fn serialize_with(_: &$type, _: &mut S) -> Result<Self::Resolver, S::Error> {
16
0
                Ok(())
17
0
            }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicBool, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI8, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU8, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI16, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI32, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI64, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU16, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU32, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU64, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicBool, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI8, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU8, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI16, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI32, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicI64, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU16, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU32, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicU64, _>>::serialize_with
18
        }
19
    };
20
    ($type:ty) => {
21
        impl ArchiveWith<$type> for Atomic {
22
            type Archived = $type;
23
            type Resolver = ();
24
25
            #[inline]
26
0
            unsafe fn resolve_with(field: &$type, _: usize, _: Self::Resolver, out: *mut Self::Archived) {
27
0
                (&*out).store(field.load(Ordering::Relaxed), Ordering::Relaxed);
28
0
            }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicBool>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI8>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU8>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicBool>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI8>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU8>>::resolve_with
29
        }
30
31
        impl_atomic!(@serialize_deserialize $type);
32
33
        impl<D: Fallible + ?Sized> DeserializeWith<$type, $type, D> for Atomic {
34
            #[inline]
35
0
            fn deserialize_with(field: &$type, _: &mut D) -> Result<$type, D::Error> {
36
0
                Ok(field.load(Ordering::Relaxed).into())
37
0
            }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicBool, core::sync::atomic::AtomicBool, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI8, core::sync::atomic::AtomicI8, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU8, core::sync::atomic::AtomicU8, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicBool, core::sync::atomic::AtomicBool, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI8, core::sync::atomic::AtomicI8, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU8, core::sync::atomic::AtomicU8, _>>::deserialize_with
38
        }
39
    };
40
    (@multibyte $type:ty) => {
41
        impl ArchiveWith<$type> for Atomic {
42
            #[cfg(not(any(feature = "archive_le", feature = "archive_be")))]
43
            type Archived = $type;
44
            #[cfg(feature = "archive_le")]
45
            type Archived = crate::rend::LittleEndian<$type>;
46
            #[cfg(feature = "archive_be")]
47
            type Archived = crate::rend::BigEndian<$type>;
48
49
            type Resolver = ();
50
51
            #[inline]
52
0
            unsafe fn resolve_with(field: &$type, _: usize, _: Self::Resolver, out: *mut Self::Archived) {
53
0
                (&*out).store(field.load(Ordering::Relaxed), Ordering::Relaxed);
54
0
            }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI16>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI32>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI64>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU16>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU32>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU64>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI16>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI32>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicI64>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU16>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU32>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicU64>>::resolve_with
55
        }
56
57
        impl_atomic!(@serialize_deserialize $type);
58
59
        impl<D: Fallible + ?Sized> DeserializeWith<Archived<With<$type, Self>>, $type, D> for Atomic {
60
            #[inline]
61
0
            fn deserialize_with(field: &Archived<With<$type, Self>>, _: &mut D) -> Result<$type, D::Error> {
62
0
                Ok(field.load(Ordering::Relaxed).into())
63
0
            }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI16, core::sync::atomic::AtomicI16, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI32, core::sync::atomic::AtomicI32, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI64, core::sync::atomic::AtomicI64, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU16, core::sync::atomic::AtomicU16, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU32, core::sync::atomic::AtomicU32, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU64, core::sync::atomic::AtomicU64, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI16, core::sync::atomic::AtomicI16, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI32, core::sync::atomic::AtomicI32, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI64, core::sync::atomic::AtomicI64, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU16, core::sync::atomic::AtomicU16, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU32, core::sync::atomic::AtomicU32, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU64, core::sync::atomic::AtomicU64, _>>::deserialize_with
64
        }
65
    };
66
}
67
68
impl_atomic!(AtomicBool);
69
impl_atomic!(AtomicI8);
70
impl_atomic!(AtomicU8);
71
72
impl_atomic!(@multibyte AtomicI16);
73
impl_atomic!(@multibyte AtomicI32);
74
#[cfg(has_atomics_64)]
75
impl_atomic!(@multibyte AtomicI64);
76
impl_atomic!(@multibyte AtomicU16);
77
impl_atomic!(@multibyte AtomicU32);
78
#[cfg(has_atomics_64)]
79
impl_atomic!(@multibyte AtomicU64);
80
81
// AtomicUsize
82
83
// We can't implement Archive for AtomicUsize if the platform does not have 64-bit atomics but the
84
// size type is 64-bit
85
#[cfg(any(has_atomics_64, not(feature = "size_64")))]
86
const _: () = {
87
    use crate::FixedUsize;
88
    use core::sync::atomic::AtomicUsize;
89
90
    #[cfg(not(has_atomics_64))]
91
    type FixedAtomicUsize = pick_size_type!(AtomicU16, AtomicU32, ());
92
    #[cfg(has_atomics_64)]
93
    type FixedAtomicUsize = pick_size_type!(AtomicU16, AtomicU32, AtomicU64);
94
95
    impl ArchiveWith<AtomicUsize> for Atomic {
96
        type Archived = Archived<With<FixedAtomicUsize, Self>>;
97
        type Resolver = ();
98
99
        #[inline]
100
0
        unsafe fn resolve_with(
101
0
            field: &AtomicUsize,
102
0
            _: usize,
103
0
            _: Self::Resolver,
104
0
            out: *mut Self::Archived,
105
0
        ) {
106
0
            (*out).store(
107
0
                field.load(Ordering::Relaxed) as FixedUsize,
108
0
                Ordering::Relaxed,
109
0
            );
110
0
        }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicUsize>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicUsize>>::resolve_with
111
    }
112
113
    impl<S: Fallible + ?Sized> SerializeWith<AtomicUsize, S> for Atomic {
114
        #[inline]
115
0
        fn serialize_with(_: &AtomicUsize, _: &mut S) -> Result<Self::Resolver, S::Error> {
116
0
            Ok(())
117
0
        }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicUsize, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicUsize, _>>::serialize_with
118
    }
119
120
    impl<D: Fallible + ?Sized>
121
        DeserializeWith<<Self as ArchiveWith<FixedAtomicUsize>>::Archived, AtomicUsize, D>
122
        for Atomic
123
    {
124
        #[inline]
125
0
        fn deserialize_with(
126
0
            field: &<Self as ArchiveWith<FixedAtomicUsize>>::Archived,
127
0
            _: &mut D,
128
0
        ) -> Result<AtomicUsize, D::Error> {
129
0
            Ok((field.load(Ordering::Relaxed) as usize).into())
130
0
        }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU32, core::sync::atomic::AtomicUsize, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicU32, core::sync::atomic::AtomicUsize, _>>::deserialize_with
131
    }
132
};
133
134
// AtomicIsize
135
136
// We can't implement Archive for AtomicIsize if the platform does not have 64-bit atomics but the
137
// size type is 64-bit
138
#[cfg(any(has_atomics_64, not(feature = "size_64")))]
139
const _: () = {
140
    use crate::FixedIsize;
141
    use core::sync::atomic::AtomicIsize;
142
143
    #[cfg(not(has_atomics_64))]
144
    type FixedAtomicIsize = pick_size_type!(AtomicI16, AtomicI32, ());
145
    #[cfg(has_atomics_64)]
146
    type FixedAtomicIsize = pick_size_type!(AtomicI16, AtomicI32, AtomicI64);
147
148
    impl ArchiveWith<AtomicIsize> for Atomic {
149
        type Archived = Archived<With<FixedAtomicIsize, Self>>;
150
        type Resolver = ();
151
152
        #[inline]
153
0
        unsafe fn resolve_with(
154
0
            field: &AtomicIsize,
155
0
            _: usize,
156
0
            _: Self::Resolver,
157
0
            out: *mut Self::Archived,
158
0
        ) {
159
0
            (*out).store(
160
0
                field.load(Ordering::Relaxed) as FixedIsize,
161
0
                Ordering::Relaxed,
162
0
            );
163
0
        }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicIsize>>::resolve_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::ArchiveWith<core::sync::atomic::AtomicIsize>>::resolve_with
164
    }
165
166
    impl<S: Fallible + ?Sized> SerializeWith<AtomicIsize, S> for Atomic {
167
        #[inline]
168
0
        fn serialize_with(_: &AtomicIsize, _: &mut S) -> Result<Self::Resolver, S::Error> {
169
0
            Ok(())
170
0
        }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicIsize, _>>::serialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::SerializeWith<core::sync::atomic::AtomicIsize, _>>::serialize_with
171
    }
172
173
    impl<D: Fallible + ?Sized> DeserializeWith<Archived<With<AtomicIsize, Self>>, AtomicIsize, D>
174
        for Atomic
175
    {
176
        #[inline]
177
0
        fn deserialize_with(
178
0
            field: &Archived<With<AtomicIsize, Self>>,
179
0
            _: &mut D,
180
0
        ) -> Result<AtomicIsize, D::Error> {
181
0
            Ok((field.load(Ordering::Relaxed) as isize).into())
182
0
        }
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI32, core::sync::atomic::AtomicIsize, _>>::deserialize_with
Unexecuted instantiation: <rkyv::with::Atomic as rkyv::with::DeserializeWith<core::sync::atomic::AtomicI32, core::sync::atomic::AtomicIsize, _>>::deserialize_with
183
    }
184
};