Struct Owned
pub struct Owned<T: ?Sized + Pointable> { /* private fields */ }
An owned heap-allocated object.
This type is very similar to Box<T>.
The pointer must be properly aligned. Since it is aligned, a tag can be stored into the unused least significant bits of the address.
Implementations
impl<T> Owned<T>
unsafe fn from_raw(raw: *mut T) -> Owned<T>Returns a new owned pointer pointing to
raw.This function is unsafe because improper use may lead to memory problems. Argument
rawmust be a valid pointer. Also, a double-free may occur if the function is called twice on the same raw pointer.Panics
Panics if
rawis not properly aligned.Safety
The given
rawshould have been derived fromOwned, and onerawshould not be converted back byOwned::from_raw()multiple times.Examples
use Owned; let o = unsafe ;fn into_box(self) -> Box<T>Converts the owned pointer into a
Box.Examples
use Owned; let o = new; let b: = o.into_box; assert_eq!;fn new(init: T) -> Owned<T>Allocates
valueon the heap and returns a new owned pointer pointing to it.Examples
use Owned; let o = new;
impl<T: ?Sized + Pointable> Owned<T>
fn init(init: T::Init) -> Owned<T>Allocates
valueon the heap and returns a new owned pointer pointing to it.Examples
use Owned; let o = init;Converts the owned pointer into a
Shared.Examples
use ; let o = new; let guard = &pin; let p = o.into_shared; # unsafe // avoid leakfn tag(&self) -> usizeReturns the tag stored within the pointer.
Examples
use Owned; assert_eq!;fn with_tag(self, tag: usize) -> Owned<T>Returns the same pointer, but tagged with
tag.tagis truncated to be fit into the unused bits of the pointer toT.Examples
use Owned; let o = new; assert_eq!; let o = o.with_tag; assert_eq!;
Trait Implementations
impl<T> From<Box<T>> for Owned<T>
fn from(b: Box<T>) -> SelfReturns a new owned pointer pointing to
b.Panics
Panics if the pointer (the
Box) is not properly aligned.Examples
use Owned; let o = unsafe ;
impl<T> From<T> for Owned<T>
fn from(t: T) -> Self
impl<T: ?Sized + Pointable> AsMut<T> for Owned<T>
fn as_mut(&mut self) -> &mut T
impl<T: ?Sized + Pointable> AsRef<T> for Owned<T>
fn as_ref(&self) -> &T
impl<T: ?Sized + Pointable> Borrow<T> for Owned<T>
fn borrow(&self) -> &T
impl<T: ?Sized + Pointable> BorrowMut<T> for Owned<T>
fn borrow_mut(&mut self) -> &mut T
impl<T: ?Sized + Pointable> Debug for Owned<T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T: ?Sized + Pointable> Deref for Owned<T>
type Target = T;fn deref(&self) -> &T
impl<T: ?Sized + Pointable> DerefMut for Owned<T>
fn deref_mut(&mut self) -> &mut T
impl<T: ?Sized + Pointable> Drop for Owned<T>
fn drop(&mut self)
impl<T: ?Sized + Pointable> Pointer<T> for Owned<T>
fn into_usize(self) -> usizeunsafe fn from_usize(data: usize) -> SelfReturns a new pointer pointing to the tagged pointer
data.Panics
Panics if the data is zero in debug mode.
impl<T: Clone> Clone for Owned<T>
fn clone(&self) -> Self
Auto Trait Implementations
impl<T> Freeze for Owned<T>
where
PhantomData<Box<T>>: Freeze,
T: ?Sized,
impl<T> RefUnwindSafe for Owned<T>
where
PhantomData<Box<T>>: RefUnwindSafe,
T: ?Sized,
impl<T> Send for Owned<T>
where
PhantomData<Box<T>>: Send,
T: ?Sized,
impl<T> Sync for Owned<T>
where
PhantomData<Box<T>>: Sync,
T: ?Sized,
impl<T> Unpin for Owned<T>
where
PhantomData<Box<T>>: Unpin,
T: ?Sized,
impl<T> UnsafeUnpin for Owned<T>
where
PhantomData<Box<T>>: UnsafeUnpin,
T: ?Sized,
impl<T> UnwindSafe for Owned<T>
where
PhantomData<Box<T>>: UnwindSafe,
T: ?Sized,
Blanket Implementations
impl<P, T> Receiver for Owned<T>
where
P: Deref<Target = T> + ?Sized,
T: ?Sized,
type Target = T;
impl<T> Any for Owned<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Owned<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Owned<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Owned<T>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Owned<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Pointable for Owned<T>
const ALIGN: usize = const ALIGN: usize = mem::align_of::<T>();;type Init = T;unsafe fn init(init: <T as Pointable>::Init) -> usizeunsafe fn deref<'a>(ptr: usize) -> &'a Tunsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Tunsafe fn drop(ptr: usize)
impl<T> ToOwned for Owned<T>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Owned<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Owned<T>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Owned<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>