Struct core::ptr::Unique [] [src]

pub struct Unique<T: ?Sized> {
    pointer: NonZero<*const T>,
    _marker: PhantomData<T>,
}
Unstable (unique #27730)

: needs an RFC to flesh out design

A wrapper around a raw *mut T that indicates that the possessor of this wrapper owns the referent. This in turn implies that the Unique<T> is Send/Sync if T is Send/Sync, unlike a raw *mut T (which conveys no particular ownership semantics). It also implies that the referent of the pointer should not be modified without a unique path to the Unique reference. Useful for building abstractions like Vec<T> or Box<T>, which internally use raw pointers to manage the memory that they own.

Fields

pointer
Unstable (unique #27730)

: needs an RFC to flesh out design

_marker
Unstable (unique #27730)

: needs an RFC to flesh out design

Methods

impl<T: ?Sized> Unique<T>

const unsafe fn new(ptr: *mut T) -> Unique<T>

Unstable (unique #27730)

Creates a new Unique.

unsafe fn get(&self) -> &T

Unstable (unique #27730)

Dereferences the content.

unsafe fn get_mut(&mut self) -> &mut T

Unstable (unique #27730)

Mutably dereferences the content.

Trait Implementations

impl<T: Send + ?Sized> Send for Unique<T>

Unique pointers are Send if T is Send because the data they reference is unaliased. Note that this aliasing invariant is unenforced by the type system; the abstraction using the Unique must enforce it.

impl<T: Sync + ?Sized> Sync for Unique<T>

Unique pointers are Sync if T is Sync because the data they reference is unaliased. Note that this aliasing invariant is unenforced by the type system; the abstraction using the Unique must enforce it.

impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U>

impl<T: ?Sized> Deref for Unique<T>

type Target = *mut T

fn deref(&self) -> &*mut T

impl<T> Pointer for Unique<T>

fn fmt(&self, f: &mut Formatter) -> Result