SmartPtr

Trait SmartPtr 

Source
pub trait SmartPtr: Sized {
    type Content: ?Sized;
    type Rebind<U: ?Sized>: SmartPtr<Content = U>;

    // Required methods
    unsafe fn from_alloc(p: *mut Self::Content) -> Self;
    unsafe fn rebind<U>(self) -> Self::Rebind<U>
       where U: Pointee<Metadata = <Self::Content as Pointee>::Metadata> + ?Sized;
}
Expand description

An abstract of smart pointers.

Required Associated Types§

Source

type Content: ?Sized

The inner type of the pointer.

Source

type Rebind<U: ?Sized>: SmartPtr<Content = U>

Rebind the smart pointer to another content type.

Required Methods§

Source

unsafe fn from_alloc(p: *mut Self::Content) -> Self

Create the smart pointer from pointer allocated from Global.

§Safety

See Box::from_raw.

Source

unsafe fn rebind<U>(self) -> Self::Rebind<U>
where U: Pointee<Metadata = <Self::Content as Pointee>::Metadata> + ?Sized,

Convert the smart pointer to another content type one.

§Safety

See std::mem::transmute.

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: ?Sized> SmartPtr for Box<T>

Source§

type Content = T

Source§

type Rebind<U: ?Sized> = Box<U>

Source§

unsafe fn from_alloc(p: *mut Self::Content) -> Self

Source§

unsafe fn rebind<U>(self) -> Self::Rebind<U>
where U: Pointee<Metadata = <Self::Content as Pointee>::Metadata> + ?Sized,

Source§

impl<T: ?Sized> SmartPtr for Rc<T>

Source§

type Content = T

Source§

type Rebind<U: ?Sized> = Rc<U>

Source§

unsafe fn from_alloc(p: *mut Self::Content) -> Self

Source§

unsafe fn rebind<U>(self) -> Self::Rebind<U>
where U: Pointee<Metadata = <Self::Content as Pointee>::Metadata> + ?Sized,

Source§

impl<T: ?Sized> SmartPtr for Arc<T>

Source§

type Content = T

Source§

type Rebind<U: ?Sized> = Arc<U>

Source§

unsafe fn from_alloc(p: *mut Self::Content) -> Self

Source§

unsafe fn rebind<U>(self) -> Self::Rebind<U>
where U: Pointee<Metadata = <Self::Content as Pointee>::Metadata> + ?Sized,

Implementors§