pub unsafe trait Storage: Sized {
// Required methods
fn new<T>(data: T) -> Self;
fn ptr(&self) -> NonNull<()>;
fn ptr_mut(&mut self) -> NonNull<()>;
unsafe fn drop_in_place(&mut self, layout: Layout);
// Provided methods
unsafe fn as_ref<T>(&self) -> &T { ... }
unsafe fn as_mut<T>(&mut self) -> &mut T { ... }
unsafe fn as_pinned_mut<T>(self: Pin<&mut Self>) -> Pin<&mut T> { ... }
}Expand description
A storage that can be used to store dynamic type-erased objects.
§Safety
ptr/ptr_mut/as_ref/as_mut/as_pinned_mut must return a pointer/reference
to stored data.
Required Methods§
Sourceunsafe fn drop_in_place(&mut self, layout: Layout)
unsafe fn drop_in_place(&mut self, layout: Layout)
Drop the storage in place with the layout of the stored data.
Stored data should have been dropped in place before calling this method.
§Safety
drop_in_place must be called once, and the storage must not be used
after. layout must be the layout of the data stored.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.