Pointer

Trait Pointer 

Source
pub trait Pointer: Sized {
    type Target;

    // Required methods
    fn as_ref(&self) -> &Self::Target;
    unsafe fn from_raw(p: *const Self::Target) -> Self;
    fn into_raw(self) -> *const Self::Target;
}
Expand description

Abstract pointer trait to support various pointer types in collections.

This trait allows the collections to work with:

  • Box<T>: Owned, automatically dropped.
  • Arc<T>: Shared ownership.
  • Rc<T>: Single thread ownership.
  • NonNull<T>: Raw non-null pointers (manual memory management).
  • *const T: Raw pointers (recommend to use NonNull<T> instead)

Required Associated Types§

Required Methods§

Source

fn as_ref(&self) -> &Self::Target

Source

unsafe fn from_raw(p: *const Self::Target) -> Self

Source

fn into_raw(self) -> *const Self::Target

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> Pointer for *const T

Source§

type Target = T

Source§

fn as_ref(&self) -> &Self::Target

Source§

unsafe fn from_raw(p: *const Self::Target) -> Self

Source§

fn into_raw(self) -> *const Self::Target

Source§

impl<T> Pointer for Box<T>

Source§

type Target = T

Source§

fn as_ref(&self) -> &Self::Target

Source§

unsafe fn from_raw(p: *const Self::Target) -> Self

Source§

fn into_raw(self) -> *const Self::Target

Source§

impl<T> Pointer for Rc<T>

Source§

type Target = T

Source§

fn as_ref(&self) -> &Self::Target

Source§

unsafe fn from_raw(p: *const Self::Target) -> Self

Source§

fn into_raw(self) -> *const Self::Target

Source§

impl<T> Pointer for Arc<T>

Source§

type Target = T

Source§

fn as_ref(&self) -> &Self::Target

Source§

unsafe fn from_raw(p: *const Self::Target) -> Self

Source§

fn into_raw(self) -> *const Self::Target

Source§

impl<T> Pointer for NonNull<T>

Source§

type Target = T

Source§

fn as_ref(&self) -> &Self::Target

Source§

unsafe fn from_raw(p: *const Self::Target) -> Self

Source§

fn into_raw(self) -> *const Self::Target

Implementors§