@@ -58,6 +58,25 @@ impl<T: ArchivePointee + ?Sized> ArchivedBox<T> {
58
58
} )
59
59
}
60
60
61
+ /// Resolves an archived box from a [`BoxResolver`] which contains
62
+ /// the raw [`<T as ArchivePointee>::ArchivedMetadata`] directly.
63
+ ///
64
+ /// # Safety
65
+ ///
66
+ /// - `pos` must be the position of `out` within the archive
67
+ /// - `resolver` must be obtained by following the safety documentation of
68
+ /// [`BoxResolver::from_raw_parts`].
69
+ ///
70
+ /// [`<T as ArchivePointee>::ArchivedMetadata`]: ArchivePointee::ArchivedMetadata
71
+ pub unsafe fn resolve_from_raw_parts (
72
+ pos : usize ,
73
+ resolver : BoxResolver < <T as ArchivePointee >:: ArchivedMetadata > ,
74
+ out : * mut Self ,
75
+ ) {
76
+ let ( fp, fo) = out_field ! ( out. 0 ) ;
77
+ RelPtr :: resolve_emplace_from_raw_parts ( pos + fp, resolver. pos , resolver. metadata_resolver , fo) ;
78
+ }
79
+
61
80
#[ doc( hidden) ]
62
81
#[ inline]
63
82
pub fn is_null ( & self ) -> bool {
@@ -190,9 +209,39 @@ impl<T: ArchivePointee + ?Sized> fmt::Pointer for ArchivedBox<T> {
190
209
}
191
210
192
211
/// The resolver for `Box`.
193
- pub struct BoxResolver < T > {
212
+ pub struct BoxResolver < M > {
194
213
pos : usize ,
195
- metadata_resolver : T ,
214
+ metadata_resolver : M ,
215
+ }
216
+
217
+ impl < M > BoxResolver < M > {
218
+ /// Createa a new [`BoxResolver<M>`] from raw parts. Note that `M` here is ***not*** the same
219
+ /// `T` which should be serialized/contained in the resulting [`ArchivedBox<T>`], and is rather
220
+ /// a type that can be used to resolve any needed [`ArchivePointee::ArchivedMetadata`]
221
+ /// for the serialized pointed-to value.
222
+ ///
223
+ /// In most cases, you won't need to create a [`BoxResolver`] yourself and can instead obtain it through
224
+ /// [`ArchivedBox::serialize_from_ref`] or [`ArchivedBox::serialize_copy_from_slice`].
225
+ ///
226
+ /// # Safety
227
+ ///
228
+ /// Constructing a valid resolver is quite fraught. Please make sure you understand what the implications are before doing it.
229
+ ///
230
+ /// - `pos`: You must ensure that you serialized and resolved (i.e. [`Serializer::serialize_value`])
231
+ /// a `T` which will be pointed to by the final [`ArchivedBox<T>`] that this resolver will help resolve
232
+ /// at the given `pos` within the archive.
233
+ ///
234
+ /// - `metadata_resolver`: You must also ensure that the given `metadata_resolver` can be used to successfully produce
235
+ /// valid [`<T as ArchivePointee>::ArchivedMetadata`] for that serialized `T`. This means it must either be:
236
+ /// - The necessary [`<T as ArchivePointee>::ArchivedMetadata`] itself, in which case you may use the created
237
+ /// [`BoxResolver<<T as ArchivePointee>::ArchivedMetadta>`] as a resolver in [`ArchivedBox::resolve_from_raw_parts`]
238
+ /// - An [`ArchiveUnsized::MetadataResolver`] obtained from some `value: &U` where `U: ArchiveUnsized<Archived = T>`, in which case you
239
+ /// must pass that same `value: &U` into [`ArchivedBox::resolve_from_ref`] along with this [`BoxResolver`].
240
+ ///
241
+ /// [`<T as ArchivePointee>::ArchivedMetadata`]: ArchivePointee::ArchivedMetadata
242
+ pub unsafe fn from_raw_parts ( pos : usize , metadata_resolver : M ) -> Self {
243
+ Self { pos, metadata_resolver }
244
+ }
196
245
}
197
246
198
247
#[ cfg( feature = "validation" ) ]
0 commit comments