pub struct Unique<'a, T: ?Sized, D: Deleter> { /* private fields */ }
Expand description
Smart pointer, that owns and manages object via its pointer.
On Drop
it automatically disposes of pointer with provided deleter.
Useful in C FFI context.
§Safety
If you use Deleter that relies on type information, you must guarantee that object was created using the same type as pointer, which points to it.
Which means you must guarantee that specified pointer is valid one and points to existing memory storage, which is already initialized.
§Trait implementation
Due to assumption that Unique
pointer always has valid value
(you need to use unsafe code to create invalid one)
All trait implementations, except pointer specific one (e.g. fmt::Pointer
), implements
corresponding traits by delegating call to underlying value.
Implementations§
Source§impl<T> Unique<'static, T, GlobalDeleter>
impl<T> Unique<'static, T, GlobalDeleter>
Source§impl<T: ?Sized> Unique<'static, T, GlobalDeleter>
impl<T: ?Sized> Unique<'static, T, GlobalDeleter>
Sourcepub fn into_boxed(self) -> Box<T>
pub fn into_boxed(self) -> Box<T>
Converts ptr to box
Source§impl<'a, T: ?Sized, D: Deleter> Unique<'a, T, D>
impl<'a, T: ?Sized, D: Deleter> Unique<'a, T, D>
Sourcepub unsafe fn from_ptr(ptr: *mut T) -> Option<Self>
pub unsafe fn from_ptr(ptr: *mut T) -> Option<Self>
Creates instance from raw pointer, checking if pointer is null.
Returns None
if pointer is null.
Sourcepub unsafe fn from_ptr_unchecked(ptr: *mut T) -> Self
pub unsafe fn from_ptr_unchecked(ptr: *mut T) -> Self
Creates instance from raw pointer, without checking if pointer is null.
User must ensure that pointer is non-null
Sourcepub fn get(&self) -> *mut T
pub fn get(&self) -> *mut T
Gets underlying raw pointer.
Note that it is illegal to create multiple mutable references so care must be taken when converting raw pointer into mutable reference.
Sourcepub fn const_cast<N>(&self) -> *const N
pub fn const_cast<N>(&self) -> *const N
Retrieves pointer as of type and const