Trait IsPtr

Source
pub trait IsPtr {
    type T: ?Sized;

    // Required methods
    fn into_raw_ptr(this: Self) -> NonNull<Self::T>;
    unsafe fn from_raw_ptr(ptr: NonNull<Self::T>) -> Self;

    // Provided method
    fn on_killed(_this: &Self) { ... }
}
Expand description

Implemented for any owning pointer which can be dereferenced as T.

§Safety

When accepting an unknown impl IsPtr, be aware of the various guarantees expected by all implementors. In particular, it may not be safe to mutate the pointer since Pin<T>: IsPtr.

Required Associated Types§

Source

type T: ?Sized

Required Methods§

Source

fn into_raw_ptr(this: Self) -> NonNull<Self::T>

Converts to the raw pointer.

Source

unsafe fn from_raw_ptr(ptr: NonNull<Self::T>) -> Self

Converts from the raw pointer. This is used mainly to call drop.

§Safety

The given pointer must have been returned by Self::into_raw_ptr.

Provided Methods§

Source

fn on_killed(_this: &Self)

An optional handler for when Own<Self> is dropped.

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 IsPtr for ()

Source§

type T = ()

Source§

fn into_raw_ptr(_: Self) -> NonNull<Self::T>

Source§

unsafe fn from_raw_ptr(_: NonNull<Self::T>) -> Self

Source§

impl IsPtr for String

Source§

type T = str

Source§

fn into_raw_ptr(this: Self) -> NonNull<str>

Source§

unsafe fn from_raw_ptr(ptr: NonNull<str>) -> Self

Source§

impl IsPtr for PathBuf

Source§

type T = Path

Source§

fn into_raw_ptr(this: Self) -> NonNull<Path>

Source§

unsafe fn from_raw_ptr(ptr: NonNull<Path>) -> Self

Source§

impl<P: IsPtr + Deref> IsPtr for Pin<P>

Source§

type T = <P as IsPtr>::T

Source§

fn into_raw_ptr(this: Self) -> NonNull<P::T>

Source§

unsafe fn from_raw_ptr(ptr: NonNull<P::T>) -> Self

Source§

impl<T> IsPtr for Vec<T>

Source§

type T = [T]

Source§

fn into_raw_ptr(this: Self) -> NonNull<[T]>

Source§

unsafe fn from_raw_ptr(ptr: NonNull<[T]>) -> Self

Source§

impl<T: ?Sized> IsPtr for Box<T>

Source§

type T = T

Source§

fn into_raw_ptr(this: Self) -> NonNull<T>

Source§

unsafe fn from_raw_ptr(ptr: NonNull<T>) -> Self

Source§

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

Source§

type T = T

Source§

fn into_raw_ptr(this: Self) -> NonNull<T>

Source§

unsafe fn from_raw_ptr(ptr: NonNull<T>) -> Self

Implementors§