rkyv::de::pooling

Trait SharedPointer

Source
pub unsafe trait SharedPointer<T: Pointee + ?Sized> {
    // Required methods
    fn alloc(metadata: T::Metadata) -> Result<*mut T, LayoutError>;
    unsafe fn from_value(ptr: *mut T) -> *mut T;
    unsafe fn drop(ptr: *mut T);
}
Expand description

A deserializable shared pointer type.

§Safety

alloc and from_value must return pointers which are non-null, writeable, and properly aligned for T.

Required Methods§

Source

fn alloc(metadata: T::Metadata) -> Result<*mut T, LayoutError>

Allocates space for a value with the given metadata.

Source

unsafe fn from_value(ptr: *mut T) -> *mut T

Creates a new Self from a pointer to a valid T.

§Safety

ptr must have been allocated via alloc. from_value must not have been called on ptr yet.

Source

unsafe fn drop(ptr: *mut T)

Drops a pointer created by from_value.

§Safety
  • ptr must have been created using from_value.
  • drop must only be called once per ptr.

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.

Implementations on Foreign Types§

Source§

impl<T: LayoutRaw + Pointee + ?Sized> SharedPointer<T> for Rc<T>

Available on crate feature alloc only.
Source§

fn alloc(metadata: T::Metadata) -> Result<*mut T, LayoutError>

Source§

unsafe fn from_value(ptr: *mut T) -> *mut T

Source§

unsafe fn drop(ptr: *mut T)

Source§

impl<T: LayoutRaw + Pointee + ?Sized> SharedPointer<T> for Arc<T>

Available on target_has_atomic="ptr" and crate feature alloc only.
Source§

fn alloc(metadata: T::Metadata) -> Result<*mut T, LayoutError>

Source§

unsafe fn from_value(ptr: *mut T) -> *mut T

Source§

unsafe fn drop(ptr: *mut T)

Implementors§