You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Consumes the `Box`, returning the wrapped pointer
188
+
pubfninto_raw(b:Self) -> *mutP::Data{
189
+
letmut b = ManuallyDrop::new(b);
190
+
// SAFETY: `b` is not dropped, so the pointer remains valid however caller must ensure that eventually it is returned to the pool
191
+
addr_of_mut!(**b)
192
+
}
193
+
194
+
/// Constructs a `Box<P>` from a raw pointer
195
+
///
196
+
/// # Safety
197
+
///
198
+
/// The `ptr` must have been allocated by the same `BoxPool` `P` that this `Box<P>` uses.
199
+
pubunsafefnfrom_raw(ptr:*mutP::Data) -> Self{
200
+
// SAFETY: caller must guarantee that `ptr` is valid and was allocated by `P`
201
+
debug_assert!(!ptr.is_null(),"Pointer must be non-null");
202
+
203
+
// Calculate the offset of the `data` field within `UnionNode` (with the current layout tha data is at the beginning so offset is zero, but this may change in the future)
204
+
let uninit_union_node = MaybeUninit::<UnionNode<MaybeUninit<P::Data>>>::uninit();
205
+
let data_ptr = unsafe{addr_of!((*uninit_union_node.as_ptr()).data)};
206
+
let data_offset = (data_ptr asusize) - (uninit_union_node.as_ptr()asusize);
0 commit comments