Skip to main content

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;

    // Provided method
    fn as_ptr(&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

§Safety

must be pointer acquire from Self::into_raw()

Source

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

Provided Methods§

Source

fn as_ptr(&self) -> *const Self::Target

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

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 *mut 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 &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§

Source§

impl<T, Tag, P> Pointer for Irc<T, Tag, P>
where T: IrcItem<Tag, P>, P: Pointer<Target = T>,

Available on crate feature irc only.