/rust/registry/src/index.crates.io-6f17d22bba15001f/rkyv-0.7.44/src/with/alloc.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::{ |
2 | | boxed::{ArchivedBox, BoxResolver}, |
3 | | collections::util::Entry, |
4 | | niche::option_box::{ArchivedOptionBox, OptionBoxResolver}, |
5 | | ser::{ScratchSpace, Serializer}, |
6 | | string::{ArchivedString, StringResolver}, |
7 | | vec::{ArchivedVec, RawArchivedVec, VecResolver}, |
8 | | with::{ |
9 | | ArchiveWith, AsOwned, AsVec, CopyOptimize, DeserializeWith, Map, Niche, Raw, RefAsBox, |
10 | | SerializeWith, With, |
11 | | }, |
12 | | Archive, ArchiveUnsized, ArchivedMetadata, Deserialize, DeserializeUnsized, Fallible, |
13 | | MetadataResolver, Serialize, SerializeUnsized, |
14 | | }; |
15 | | use ::core::marker::PhantomData; |
16 | | #[cfg(not(feature = "std"))] |
17 | | use alloc::{ |
18 | | borrow::Cow, |
19 | | boxed::Box, |
20 | | collections::{BTreeMap, BTreeSet}, |
21 | | vec::Vec, |
22 | | }; |
23 | | #[cfg(feature = "std")] |
24 | | use std::{ |
25 | | borrow::Cow, |
26 | | boxed::Box, |
27 | | collections::{BTreeMap, BTreeSet}, |
28 | | }; |
29 | | |
30 | | // Map for Vecs |
31 | | |
32 | | impl<A, O> ArchiveWith<Vec<O>> for Map<A> |
33 | | where |
34 | | A: ArchiveWith<O>, |
35 | | { |
36 | | type Archived = ArchivedVec<<A as ArchiveWith<O>>::Archived>; |
37 | | type Resolver = VecResolver; |
38 | | |
39 | 0 | unsafe fn resolve_with( |
40 | 0 | field: &Vec<O>, |
41 | 0 | pos: usize, |
42 | 0 | resolver: Self::Resolver, |
43 | 0 | out: *mut Self::Archived, |
44 | 0 | ) { |
45 | 0 | ArchivedVec::resolve_from_len(field.len(), pos, resolver, out) |
46 | 0 | } Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::ArchiveWith<alloc::vec::Vec<_>>>::resolve_with Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::ArchiveWith<alloc::vec::Vec<_>>>::resolve_with |
47 | | } |
48 | | |
49 | | impl<A, O, S> SerializeWith<Vec<O>, S> for Map<A> |
50 | | where |
51 | | S: Fallible + ScratchSpace + Serializer + ?Sized, |
52 | | A: ArchiveWith<O> + SerializeWith<O, S>, |
53 | | { |
54 | 0 | fn serialize_with(field: &Vec<O>, s: &mut S) -> Result<Self::Resolver, S::Error> { |
55 | 0 | // Wrapper for O so that we have an Archive and Serialize implementation |
56 | 0 | // and ArchivedVec::serialize_from_* is happy about the bound constraints |
57 | 0 | struct RefWrapper<'o, A, O>(&'o O, PhantomData<A>); |
58 | 0 |
|
59 | 0 | impl<A: ArchiveWith<O>, O> Archive for RefWrapper<'_, A, O> { |
60 | 0 | type Archived = <A as ArchiveWith<O>>::Archived; |
61 | 0 | type Resolver = <A as ArchiveWith<O>>::Resolver; |
62 | 0 |
|
63 | 0 | unsafe fn resolve( |
64 | 0 | &self, |
65 | 0 | pos: usize, |
66 | 0 | resolver: Self::Resolver, |
67 | 0 | out: *mut Self::Archived, |
68 | 0 | ) { |
69 | 0 | A::resolve_with(self.0, pos, resolver, out) |
70 | 0 | } Unexecuted instantiation: <<rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with::RefWrapper<_, _> as rkyv::Archive>::resolve Unexecuted instantiation: <<rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with::RefWrapper<_, _> as rkyv::Archive>::resolve |
71 | 0 | } |
72 | 0 |
|
73 | 0 | impl<A, O, S> Serialize<S> for RefWrapper<'_, A, O> |
74 | 0 | where |
75 | 0 | A: ArchiveWith<O> + SerializeWith<O, S>, |
76 | 0 | S: Fallible + Serializer + ?Sized, |
77 | 0 | { |
78 | 0 | fn serialize(&self, s: &mut S) -> Result<Self::Resolver, S::Error> { |
79 | 0 | A::serialize_with(self.0, s) |
80 | 0 | } Unexecuted instantiation: <<rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with::RefWrapper<_, _> as rkyv::Serialize<_>>::serialize Unexecuted instantiation: <<rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with::RefWrapper<_, _> as rkyv::Serialize<_>>::serialize |
81 | 0 | } |
82 | 0 |
|
83 | 0 | let iter = field |
84 | 0 | .iter() |
85 | 0 | .map(|value| RefWrapper::<'_, A, O>(value, PhantomData)); Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with::{closure#0}Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with::{closure#0} |
86 | 0 |
|
87 | 0 | ArchivedVec::serialize_from_iter(iter, s) |
88 | 0 | } Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with |
89 | | } |
90 | | |
91 | | impl<A, O, D> DeserializeWith<ArchivedVec<<A as ArchiveWith<O>>::Archived>, Vec<O>, D> for Map<A> |
92 | | where |
93 | | A: ArchiveWith<O> + DeserializeWith<<A as ArchiveWith<O>>::Archived, O, D>, |
94 | | D: Fallible + ?Sized, |
95 | | { |
96 | 0 | fn deserialize_with( |
97 | 0 | field: &ArchivedVec<<A as ArchiveWith<O>>::Archived>, |
98 | 0 | d: &mut D, |
99 | 0 | ) -> Result<Vec<O>, D::Error> { |
100 | 0 | field |
101 | 0 | .iter() |
102 | 0 | .map(|value| <A as DeserializeWith<_, _, D>>::deserialize_with(value, d)) Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::with::ArchiveWith<_>>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with::{closure#0}Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::with::ArchiveWith<_>>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with::{closure#0} |
103 | 0 | .collect() |
104 | 0 | } Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::with::ArchiveWith<_>>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::Map<_> as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::with::ArchiveWith<_>>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with |
105 | | } |
106 | | |
107 | | // AsOwned |
108 | | |
109 | | impl<'a, F: Archive + Clone> ArchiveWith<Cow<'a, F>> for AsOwned { |
110 | | type Archived = F::Archived; |
111 | | type Resolver = F::Resolver; |
112 | | |
113 | | #[inline] |
114 | 0 | unsafe fn resolve_with( |
115 | 0 | field: &Cow<'a, F>, |
116 | 0 | pos: usize, |
117 | 0 | resolver: Self::Resolver, |
118 | 0 | out: *mut Self::Archived, |
119 | 0 | ) { |
120 | 0 | field.resolve(pos, resolver, out); |
121 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<_>>>::resolve_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<_>>>::resolve_with |
122 | | } |
123 | | |
124 | | impl<'a, F: Serialize<S> + Clone, S: Fallible + ?Sized> SerializeWith<Cow<'a, F>, S> for AsOwned { |
125 | | #[inline] |
126 | 0 | fn serialize_with(field: &Cow<'a, F>, serializer: &mut S) -> Result<Self::Resolver, S::Error> { |
127 | 0 | field.serialize(serializer) |
128 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<_>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<_>, _>>::serialize_with |
129 | | } |
130 | | |
131 | | impl<T: Archive + Clone, D: Fallible + ?Sized> DeserializeWith<T::Archived, T, D> for AsOwned |
132 | | where |
133 | | T::Archived: Deserialize<T, D>, |
134 | | { |
135 | | #[inline] |
136 | 0 | fn deserialize_with(field: &T::Archived, deserializer: &mut D) -> Result<T, D::Error> { |
137 | 0 | field.deserialize(deserializer) |
138 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<<_ as rkyv::Archive>::Archived, _, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<<_ as rkyv::Archive>::Archived, _, _>>::deserialize_with |
139 | | } |
140 | | |
141 | | impl<'a, T: Archive + Clone> ArchiveWith<Cow<'a, [T]>> for AsOwned { |
142 | | type Archived = ArchivedVec<T::Archived>; |
143 | | type Resolver = VecResolver; |
144 | | |
145 | | #[inline] |
146 | 0 | unsafe fn resolve_with( |
147 | 0 | field: &Cow<'a, [T]>, |
148 | 0 | pos: usize, |
149 | 0 | resolver: Self::Resolver, |
150 | 0 | out: *mut Self::Archived, |
151 | 0 | ) { |
152 | 0 | ArchivedVec::resolve_from_slice(field, pos, resolver, out); |
153 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<[_]>>>::resolve_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<[_]>>>::resolve_with |
154 | | } |
155 | | |
156 | | impl<'a, T: Serialize<S> + Clone, S: ScratchSpace + Serializer + ?Sized> |
157 | | SerializeWith<Cow<'a, [T]>, S> for AsOwned |
158 | | { |
159 | | #[inline] |
160 | 0 | fn serialize_with( |
161 | 0 | field: &Cow<'a, [T]>, |
162 | 0 | serializer: &mut S, |
163 | 0 | ) -> Result<Self::Resolver, S::Error> { |
164 | 0 | ArchivedVec::serialize_from_slice(field, serializer) |
165 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<[_]>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<[_]>, _>>::serialize_with |
166 | | } |
167 | | |
168 | | impl<'a, T, D> DeserializeWith<ArchivedVec<T::Archived>, Cow<'a, [T]>, D> for AsOwned |
169 | | where |
170 | | T: Archive + Clone, |
171 | | T::Archived: Deserialize<T, D>, |
172 | | D: Fallible + ?Sized, |
173 | | { |
174 | | #[inline] |
175 | 0 | fn deserialize_with( |
176 | 0 | field: &ArchivedVec<T::Archived>, |
177 | 0 | deserializer: &mut D, |
178 | 0 | ) -> Result<Cow<'a, [T]>, D::Error> { |
179 | 0 | Ok(Cow::Owned(field.deserialize(deserializer)?)) |
180 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::borrow::Cow<[_]>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::borrow::Cow<[_]>, _>>::deserialize_with |
181 | | } |
182 | | |
183 | | impl<'a> ArchiveWith<Cow<'a, str>> for AsOwned { |
184 | | type Archived = ArchivedString; |
185 | | type Resolver = StringResolver; |
186 | | |
187 | | #[inline] |
188 | 0 | unsafe fn resolve_with( |
189 | 0 | field: &Cow<'a, str>, |
190 | 0 | pos: usize, |
191 | 0 | resolver: Self::Resolver, |
192 | 0 | out: *mut Self::Archived, |
193 | 0 | ) { |
194 | 0 | ArchivedString::resolve_from_str(field, pos, resolver, out); |
195 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<str>>>::resolve_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<str>>>::resolve_with |
196 | | } |
197 | | |
198 | | impl<'a, S: Serializer + ?Sized> SerializeWith<Cow<'a, str>, S> for AsOwned { |
199 | | #[inline] |
200 | 0 | fn serialize_with( |
201 | 0 | field: &Cow<'a, str>, |
202 | 0 | serializer: &mut S, |
203 | 0 | ) -> Result<Self::Resolver, S::Error> { |
204 | 0 | ArchivedString::serialize_from_str(field, serializer) |
205 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<str>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<str>, _>>::serialize_with |
206 | | } |
207 | | |
208 | | impl<'a, D: Fallible + ?Sized> DeserializeWith<ArchivedString, Cow<'a, str>, D> for AsOwned { |
209 | | #[inline] |
210 | 0 | fn deserialize_with( |
211 | 0 | field: &ArchivedString, |
212 | 0 | deserializer: &mut D, |
213 | 0 | ) -> Result<Cow<'a, str>, D::Error> { |
214 | 0 | Ok(Cow::Owned(field.deserialize(deserializer)?)) |
215 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<rkyv::string::ArchivedString, alloc::borrow::Cow<str>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<rkyv::string::ArchivedString, alloc::borrow::Cow<str>, _>>::deserialize_with |
216 | | } |
217 | | |
218 | | #[cfg(feature = "std")] |
219 | | const _: () = { |
220 | | use crate::ffi::{ArchivedCString, CStringResolver}; |
221 | | use std::ffi::CStr; |
222 | | |
223 | | impl<'a> ArchiveWith<Cow<'a, CStr>> for AsOwned { |
224 | | type Archived = ArchivedCString; |
225 | | type Resolver = CStringResolver; |
226 | | |
227 | | #[inline] |
228 | 0 | unsafe fn resolve_with( |
229 | 0 | field: &Cow<'a, CStr>, |
230 | 0 | pos: usize, |
231 | 0 | resolver: Self::Resolver, |
232 | 0 | out: *mut Self::Archived, |
233 | 0 | ) { |
234 | 0 | ArchivedCString::resolve_from_c_str(field, pos, resolver, out); |
235 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<core::ffi::c_str::CStr>>>::resolve_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::ArchiveWith<alloc::borrow::Cow<core::ffi::c_str::CStr>>>::resolve_with |
236 | | } |
237 | | |
238 | | impl<'a, S: Serializer + ?Sized> SerializeWith<Cow<'a, CStr>, S> for AsOwned { |
239 | | #[inline] |
240 | 0 | fn serialize_with( |
241 | 0 | field: &Cow<'a, CStr>, |
242 | 0 | serializer: &mut S, |
243 | 0 | ) -> Result<Self::Resolver, S::Error> { |
244 | 0 | ArchivedCString::serialize_from_c_str(field, serializer) |
245 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<core::ffi::c_str::CStr>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::SerializeWith<alloc::borrow::Cow<core::ffi::c_str::CStr>, _>>::serialize_with |
246 | | } |
247 | | |
248 | | impl<'a, D: Fallible + ?Sized> DeserializeWith<ArchivedCString, Cow<'a, CStr>, D> for AsOwned { |
249 | | #[inline] |
250 | 0 | fn deserialize_with( |
251 | 0 | field: &ArchivedCString, |
252 | 0 | deserializer: &mut D, |
253 | 0 | ) -> Result<Cow<'a, CStr>, D::Error> { |
254 | 0 | Ok(Cow::Owned(field.deserialize(deserializer)?)) |
255 | 0 | } Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<rkyv::ffi::ArchivedCString, alloc::borrow::Cow<core::ffi::c_str::CStr>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::AsOwned as rkyv::with::DeserializeWith<rkyv::ffi::ArchivedCString, alloc::borrow::Cow<core::ffi::c_str::CStr>, _>>::deserialize_with |
256 | | } |
257 | | }; |
258 | | |
259 | | // AsVec |
260 | | |
261 | | impl<K: Archive, V: Archive> ArchiveWith<BTreeMap<K, V>> for AsVec { |
262 | | type Archived = ArchivedVec<Entry<K::Archived, V::Archived>>; |
263 | | type Resolver = VecResolver; |
264 | | |
265 | 0 | unsafe fn resolve_with( |
266 | 0 | field: &BTreeMap<K, V>, |
267 | 0 | pos: usize, |
268 | 0 | resolver: Self::Resolver, |
269 | 0 | out: *mut Self::Archived, |
270 | 0 | ) { |
271 | 0 | ArchivedVec::resolve_from_len(field.len(), pos, resolver, out); |
272 | 0 | } Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::ArchiveWith<alloc::collections::btree::map::BTreeMap<_, _>>>::resolve_with Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::ArchiveWith<alloc::collections::btree::map::BTreeMap<_, _>>>::resolve_with |
273 | | } |
274 | | |
275 | | impl<K, V, S> SerializeWith<BTreeMap<K, V>, S> for AsVec |
276 | | where |
277 | | K: Serialize<S>, |
278 | | V: Serialize<S>, |
279 | | S: ScratchSpace + Serializer + ?Sized, |
280 | | { |
281 | 0 | fn serialize_with( |
282 | 0 | field: &BTreeMap<K, V>, |
283 | 0 | serializer: &mut S, |
284 | 0 | ) -> Result<Self::Resolver, S::Error> { |
285 | 0 | ArchivedVec::serialize_from_iter( |
286 | 0 | field.iter().map(|(key, value)| Entry { key, value }),Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::SerializeWith<alloc::collections::btree::map::BTreeMap<_, _>, _>>::serialize_with::{closure#0}Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::SerializeWith<alloc::collections::btree::map::BTreeMap<_, _>, _>>::serialize_with::{closure#0} |
287 | 0 | serializer, |
288 | 0 | ) |
289 | 0 | } Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::SerializeWith<alloc::collections::btree::map::BTreeMap<_, _>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::SerializeWith<alloc::collections::btree::map::BTreeMap<_, _>, _>>::serialize_with |
290 | | } |
291 | | |
292 | | impl<K, V, D> DeserializeWith<ArchivedVec<Entry<K::Archived, V::Archived>>, BTreeMap<K, V>, D> |
293 | | for AsVec |
294 | | where |
295 | | K: Archive + Ord, |
296 | | V: Archive, |
297 | | K::Archived: Deserialize<K, D>, |
298 | | V::Archived: Deserialize<V, D>, |
299 | | D: Fallible + ?Sized, |
300 | | { |
301 | 0 | fn deserialize_with( |
302 | 0 | field: &ArchivedVec<Entry<K::Archived, V::Archived>>, |
303 | 0 | deserializer: &mut D, |
304 | 0 | ) -> Result<BTreeMap<K, V>, D::Error> { |
305 | 0 | let mut result = BTreeMap::new(); |
306 | 0 | for entry in field.iter() { |
307 | 0 | result.insert( |
308 | 0 | entry.key.deserialize(deserializer)?, |
309 | 0 | entry.value.deserialize(deserializer)?, |
310 | | ); |
311 | | } |
312 | 0 | Ok(result) |
313 | 0 | } Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<rkyv::collections::util::Entry<<_ as rkyv::Archive>::Archived, <_ as rkyv::Archive>::Archived>>, alloc::collections::btree::map::BTreeMap<_, _>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<rkyv::collections::util::Entry<<_ as rkyv::Archive>::Archived, <_ as rkyv::Archive>::Archived>>, alloc::collections::btree::map::BTreeMap<_, _>, _>>::deserialize_with |
314 | | } |
315 | | |
316 | | impl<T: Archive> ArchiveWith<BTreeSet<T>> for AsVec { |
317 | | type Archived = ArchivedVec<T::Archived>; |
318 | | type Resolver = VecResolver; |
319 | | |
320 | 0 | unsafe fn resolve_with( |
321 | 0 | field: &BTreeSet<T>, |
322 | 0 | pos: usize, |
323 | 0 | resolver: Self::Resolver, |
324 | 0 | out: *mut Self::Archived, |
325 | 0 | ) { |
326 | 0 | ArchivedVec::resolve_from_len(field.len(), pos, resolver, out); |
327 | 0 | } Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::ArchiveWith<alloc::collections::btree::set::BTreeSet<_>>>::resolve_with Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::ArchiveWith<alloc::collections::btree::set::BTreeSet<_>>>::resolve_with |
328 | | } |
329 | | |
330 | | impl<T, S> SerializeWith<BTreeSet<T>, S> for AsVec |
331 | | where |
332 | | T: Serialize<S>, |
333 | | S: ScratchSpace + Serializer + ?Sized, |
334 | | { |
335 | 0 | fn serialize_with(field: &BTreeSet<T>, serializer: &mut S) -> Result<Self::Resolver, S::Error> { |
336 | 0 | ArchivedVec::<T::Archived>::serialize_from_iter::<T, _, _, _>(field.iter(), serializer) |
337 | 0 | } Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::SerializeWith<alloc::collections::btree::set::BTreeSet<_>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::SerializeWith<alloc::collections::btree::set::BTreeSet<_>, _>>::serialize_with |
338 | | } |
339 | | |
340 | | impl<T, D> DeserializeWith<ArchivedVec<T::Archived>, BTreeSet<T>, D> for AsVec |
341 | | where |
342 | | T: Archive + Ord, |
343 | | T::Archived: Deserialize<T, D>, |
344 | | D: Fallible + ?Sized, |
345 | | { |
346 | 0 | fn deserialize_with( |
347 | 0 | field: &ArchivedVec<T::Archived>, |
348 | 0 | deserializer: &mut D, |
349 | 0 | ) -> Result<BTreeSet<T>, D::Error> { |
350 | 0 | let mut result = BTreeSet::new(); |
351 | 0 | for key in field.iter() { |
352 | 0 | result.insert(key.deserialize(deserializer)?); |
353 | | } |
354 | 0 | Ok(result) |
355 | 0 | } Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::collections::btree::set::BTreeSet<_>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::AsVec as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::collections::btree::set::BTreeSet<_>, _>>::deserialize_with |
356 | | } |
357 | | |
358 | | // Niche |
359 | | |
360 | | impl<T: ArchiveUnsized + ?Sized> ArchiveWith<Option<Box<T>>> for Niche |
361 | | where |
362 | | ArchivedMetadata<T>: Default, |
363 | | { |
364 | | type Archived = ArchivedOptionBox<T::Archived>; |
365 | | type Resolver = OptionBoxResolver<T::MetadataResolver>; |
366 | | |
367 | 0 | unsafe fn resolve_with( |
368 | 0 | field: &Option<Box<T>>, |
369 | 0 | pos: usize, |
370 | 0 | resolver: Self::Resolver, |
371 | 0 | out: *mut Self::Archived, |
372 | 0 | ) { |
373 | 0 | ArchivedOptionBox::resolve_from_option(field.as_deref(), pos, resolver, out); |
374 | 0 | } Unexecuted instantiation: <rkyv::with::Niche as rkyv::with::ArchiveWith<core::option::Option<alloc::boxed::Box<_>>>>::resolve_with Unexecuted instantiation: <rkyv::with::Niche as rkyv::with::ArchiveWith<core::option::Option<alloc::boxed::Box<_>>>>::resolve_with |
375 | | } |
376 | | |
377 | | impl<T, S> SerializeWith<Option<Box<T>>, S> for Niche |
378 | | where |
379 | | T: SerializeUnsized<S> + ?Sized, |
380 | | S: Serializer + ?Sized, |
381 | | ArchivedMetadata<T>: Default, |
382 | | { |
383 | 0 | fn serialize_with( |
384 | 0 | field: &Option<Box<T>>, |
385 | 0 | serializer: &mut S, |
386 | 0 | ) -> Result<Self::Resolver, S::Error> { |
387 | 0 | ArchivedOptionBox::serialize_from_option(field.as_deref(), serializer) |
388 | 0 | } Unexecuted instantiation: <rkyv::with::Niche as rkyv::with::SerializeWith<core::option::Option<alloc::boxed::Box<_>>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::Niche as rkyv::with::SerializeWith<core::option::Option<alloc::boxed::Box<_>>, _>>::serialize_with |
389 | | } |
390 | | |
391 | | impl<T, D> DeserializeWith<ArchivedOptionBox<T::Archived>, Option<Box<T>>, D> for Niche |
392 | | where |
393 | | T: ArchiveUnsized + ?Sized, |
394 | | T::Archived: DeserializeUnsized<T, D>, |
395 | | D: Fallible + ?Sized, |
396 | | { |
397 | 0 | fn deserialize_with( |
398 | 0 | field: &ArchivedOptionBox<T::Archived>, |
399 | 0 | deserializer: &mut D, |
400 | 0 | ) -> Result<Option<Box<T>>, D::Error> { |
401 | 0 | if let Some(value) = field.as_ref() { |
402 | 0 | Ok(Some(value.deserialize(deserializer)?)) |
403 | | } else { |
404 | 0 | Ok(None) |
405 | | } |
406 | 0 | } Unexecuted instantiation: <rkyv::with::Niche as rkyv::with::DeserializeWith<rkyv::niche::option_box::ArchivedOptionBox<<_ as rkyv::ArchiveUnsized>::Archived>, core::option::Option<alloc::boxed::Box<_>>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::Niche as rkyv::with::DeserializeWith<rkyv::niche::option_box::ArchivedOptionBox<<_ as rkyv::ArchiveUnsized>::Archived>, core::option::Option<alloc::boxed::Box<_>>, _>>::deserialize_with |
407 | | } |
408 | | |
409 | | // CopyOptimize |
410 | | |
411 | | impl<T: Archive> ArchiveWith<Vec<T>> for CopyOptimize { |
412 | | type Archived = ArchivedVec<T::Archived>; |
413 | | type Resolver = VecResolver; |
414 | | |
415 | 0 | unsafe fn resolve_with( |
416 | 0 | field: &Vec<T>, |
417 | 0 | pos: usize, |
418 | 0 | resolver: Self::Resolver, |
419 | 0 | out: *mut Self::Archived, |
420 | 0 | ) { |
421 | 0 | ArchivedVec::resolve_from_len(field.len(), pos, resolver, out); |
422 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::ArchiveWith<alloc::vec::Vec<_>>>::resolve_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::ArchiveWith<alloc::vec::Vec<_>>>::resolve_with |
423 | | } |
424 | | |
425 | | impl<T, S> SerializeWith<Vec<T>, S> for CopyOptimize |
426 | | where |
427 | | T: Serialize<S>, |
428 | | S: Serializer + ?Sized, |
429 | | { |
430 | 0 | fn serialize_with(field: &Vec<T>, serializer: &mut S) -> Result<Self::Resolver, S::Error> { |
431 | 0 | use ::core::mem::size_of; |
432 | 0 |
|
433 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
434 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
435 | | |
436 | 0 | unsafe { ArchivedVec::serialize_copy_from_slice(field.as_slice(), serializer) } |
437 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with |
438 | | } |
439 | | |
440 | | impl<T, D> DeserializeWith<ArchivedVec<T::Archived>, Vec<T>, D> for CopyOptimize |
441 | | where |
442 | | T: Archive, |
443 | | T::Archived: Deserialize<T, D>, |
444 | | D: Fallible + ?Sized, |
445 | | { |
446 | 0 | fn deserialize_with(field: &ArchivedVec<T::Archived>, _: &mut D) -> Result<Vec<T>, D::Error> { |
447 | 0 | use ::core::{mem::size_of, ptr::copy_nonoverlapping}; |
448 | 0 |
|
449 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
450 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
451 | | |
452 | 0 | let mut result = Vec::with_capacity(field.len()); |
453 | 0 | unsafe { |
454 | 0 | copy_nonoverlapping(field.as_ptr().cast(), result.as_mut_ptr(), field.len()); |
455 | 0 | result.set_len(field.len()); |
456 | 0 | } |
457 | 0 |
|
458 | 0 | Ok(result) |
459 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::DeserializeWith<rkyv::vec::ArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with |
460 | | } |
461 | | |
462 | | impl<T: Archive> ArchiveWith<Box<[T]>> for CopyOptimize { |
463 | | type Archived = ArchivedBox<[T::Archived]>; |
464 | | type Resolver = BoxResolver<MetadataResolver<[T]>>; |
465 | | |
466 | 0 | unsafe fn resolve_with( |
467 | 0 | field: &Box<[T]>, |
468 | 0 | pos: usize, |
469 | 0 | resolver: Self::Resolver, |
470 | 0 | out: *mut Self::Archived, |
471 | 0 | ) { |
472 | 0 | ArchivedBox::resolve_from_ref(&**field, pos, resolver, out); |
473 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::ArchiveWith<alloc::boxed::Box<[_]>>>::resolve_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::ArchiveWith<alloc::boxed::Box<[_]>>>::resolve_with |
474 | | } |
475 | | |
476 | | impl<T, S> SerializeWith<Box<[T]>, S> for CopyOptimize |
477 | | where |
478 | | T: Serialize<S>, |
479 | | S: Serializer + ?Sized, |
480 | | { |
481 | 0 | fn serialize_with(field: &Box<[T]>, serializer: &mut S) -> Result<Self::Resolver, S::Error> { |
482 | 0 | use ::core::mem::size_of; |
483 | 0 |
|
484 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
485 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
486 | | |
487 | 0 | unsafe { ArchivedBox::<[T::Archived]>::serialize_copy_from_slice(field, serializer) } |
488 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::SerializeWith<alloc::boxed::Box<[_]>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::SerializeWith<alloc::boxed::Box<[_]>, _>>::serialize_with |
489 | | } |
490 | | |
491 | | impl<T, D> DeserializeWith<ArchivedBox<[T::Archived]>, Box<[T]>, D> for CopyOptimize |
492 | | where |
493 | | T: Archive, |
494 | | T::Archived: Deserialize<T, D>, |
495 | | D: Fallible + ?Sized, |
496 | | { |
497 | 0 | fn deserialize_with( |
498 | 0 | field: &ArchivedBox<[T::Archived]>, |
499 | 0 | _: &mut D, |
500 | 0 | ) -> Result<Box<[T]>, D::Error> { |
501 | 0 | use ::core::{mem::size_of, ptr::copy_nonoverlapping}; |
502 | 0 |
|
503 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
504 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
505 | | |
506 | 0 | let mut result = Vec::with_capacity(field.len()); |
507 | 0 | unsafe { |
508 | 0 | copy_nonoverlapping(field.as_ptr().cast(), result.as_mut_ptr(), field.len()); |
509 | 0 | result.set_len(field.len()); |
510 | 0 | } |
511 | 0 |
|
512 | 0 | Ok(result.into_boxed_slice()) |
513 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::DeserializeWith<rkyv::boxed::ArchivedBox<[<_ as rkyv::Archive>::Archived]>, alloc::boxed::Box<[_]>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::DeserializeWith<rkyv::boxed::ArchivedBox<[<_ as rkyv::Archive>::Archived]>, alloc::boxed::Box<[_]>, _>>::deserialize_with |
514 | | } |
515 | | |
516 | | impl<'a, T: Archive> ArchiveWith<With<&'a [T], RefAsBox>> for CopyOptimize { |
517 | | type Archived = ArchivedBox<[T::Archived]>; |
518 | | type Resolver = BoxResolver<MetadataResolver<[T]>>; |
519 | | |
520 | 0 | unsafe fn resolve_with( |
521 | 0 | field: &With<&'a [T], RefAsBox>, |
522 | 0 | pos: usize, |
523 | 0 | resolver: Self::Resolver, |
524 | 0 | out: *mut Self::Archived, |
525 | 0 | ) { |
526 | 0 | ArchivedBox::resolve_from_ref(*field.as_ref(), pos, resolver, out); |
527 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::ArchiveWith<rkyv::with::With<&[_], rkyv::with::RefAsBox>>>::resolve_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::ArchiveWith<rkyv::with::With<&[_], rkyv::with::RefAsBox>>>::resolve_with |
528 | | } |
529 | | |
530 | | impl<'a, T, S> SerializeWith<With<&'a [T], RefAsBox>, S> for CopyOptimize |
531 | | where |
532 | | T: Serialize<S>, |
533 | | S: Serializer + ?Sized, |
534 | | { |
535 | 0 | fn serialize_with( |
536 | 0 | field: &With<&'a [T], RefAsBox>, |
537 | 0 | serializer: &mut S, |
538 | 0 | ) -> Result<Self::Resolver, S::Error> { |
539 | 0 | use ::core::mem::size_of; |
540 | 0 |
|
541 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
542 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
543 | | |
544 | | unsafe { |
545 | 0 | ArchivedBox::<[T::Archived]>::serialize_copy_from_slice(field.as_ref(), serializer) |
546 | 0 | } |
547 | 0 | } Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::SerializeWith<rkyv::with::With<&[_], rkyv::with::RefAsBox>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::CopyOptimize as rkyv::with::SerializeWith<rkyv::with::With<&[_], rkyv::with::RefAsBox>, _>>::serialize_with |
548 | | } |
549 | | |
550 | | // Raw |
551 | | |
552 | | impl<T: Archive> ArchiveWith<Vec<T>> for Raw { |
553 | | type Archived = RawArchivedVec<T::Archived>; |
554 | | type Resolver = VecResolver; |
555 | | |
556 | 0 | unsafe fn resolve_with( |
557 | 0 | field: &Vec<T>, |
558 | 0 | pos: usize, |
559 | 0 | resolver: Self::Resolver, |
560 | 0 | out: *mut Self::Archived, |
561 | 0 | ) { |
562 | 0 | RawArchivedVec::resolve_from_slice(field.as_slice(), pos, resolver, out); |
563 | 0 | } Unexecuted instantiation: <rkyv::with::Raw as rkyv::with::ArchiveWith<alloc::vec::Vec<_>>>::resolve_with Unexecuted instantiation: <rkyv::with::Raw as rkyv::with::ArchiveWith<alloc::vec::Vec<_>>>::resolve_with |
564 | | } |
565 | | |
566 | | impl<T, S> SerializeWith<Vec<T>, S> for Raw |
567 | | where |
568 | | T: Serialize<S>, |
569 | | S: Serializer + ?Sized, |
570 | | { |
571 | 0 | fn serialize_with(field: &Vec<T>, serializer: &mut S) -> Result<Self::Resolver, S::Error> { |
572 | 0 | use ::core::mem::size_of; |
573 | 0 |
|
574 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
575 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
576 | | |
577 | 0 | unsafe { ArchivedVec::serialize_copy_from_slice(field.as_slice(), serializer) } |
578 | 0 | } Unexecuted instantiation: <rkyv::with::Raw as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with Unexecuted instantiation: <rkyv::with::Raw as rkyv::with::SerializeWith<alloc::vec::Vec<_>, _>>::serialize_with |
579 | | } |
580 | | |
581 | | impl<T, D> DeserializeWith<RawArchivedVec<T::Archived>, Vec<T>, D> for Raw |
582 | | where |
583 | | T: Archive, |
584 | | T::Archived: Deserialize<T, D>, |
585 | | D: Fallible + ?Sized, |
586 | | { |
587 | 0 | fn deserialize_with( |
588 | 0 | field: &RawArchivedVec<T::Archived>, |
589 | 0 | _: &mut D, |
590 | 0 | ) -> Result<Vec<T>, D::Error> { |
591 | 0 | use ::core::{mem::size_of, ptr::copy_nonoverlapping}; |
592 | 0 |
|
593 | 0 | // Basic debug assert that T and T::Archived are at least the same size |
594 | 0 | debug_assert_eq!(size_of::<T>(), size_of::<T::Archived>()); |
595 | | |
596 | 0 | let mut result = Vec::with_capacity(field.len()); |
597 | 0 | unsafe { |
598 | 0 | copy_nonoverlapping(field.as_ptr().cast(), result.as_mut_ptr(), field.len()); |
599 | 0 | result.set_len(field.len()); |
600 | 0 | } |
601 | 0 |
|
602 | 0 | Ok(result) |
603 | 0 | } Unexecuted instantiation: <rkyv::with::Raw as rkyv::with::DeserializeWith<rkyv::vec::raw::RawArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with Unexecuted instantiation: <rkyv::with::Raw as rkyv::with::DeserializeWith<rkyv::vec::raw::RawArchivedVec<<_ as rkyv::Archive>::Archived>, alloc::vec::Vec<_>, _>>::deserialize_with |
604 | | } |