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 raw must be a valid pointer. Also, a double-free may occur if the function is called twice on the same raw pointer.

Panics

Panics if raw is not properly aligned.

Safety

The given raw should have been derived from Owned, and one raw should not be converted back by Owned::from_raw() multiple times.

Examples

use crossbeam_epoch::Owned;

let o = unsafe { Owned::from_raw(Box::into_raw(Box::new(1234))) };
fn into_box(self) -> Box<T>

Converts the owned pointer into a Box.

Examples

use crossbeam_epoch::Owned;

let o = Owned::new(1234);
let b: Box<i32> = o.into_box();
assert_eq!(*b, 1234);
fn new(init: T) -> Owned<T>

Allocates value on the heap and returns a new owned pointer pointing to it.

Examples

use crossbeam_epoch::Owned;

let o = Owned::new(1234);

impl<T: ?Sized + Pointable> Owned<T>

fn init(init: T::Init) -> Owned<T>

Allocates value on the heap and returns a new owned pointer pointing to it.

Examples

use crossbeam_epoch::Owned;

let o = Owned::<i32>::init(1234);
fn into_shared<'g>(self, &'g Guard) -> Shared<'g, T>

Converts the owned pointer into a Shared.

Examples

use crossbeam_epoch::{self as epoch, Owned};

let o = Owned::new(1234);
let guard = &epoch::pin();
let p = o.into_shared(guard);
# unsafe { drop(p.into_owned()); } // avoid leak
fn tag(&self) -> usize

Returns the tag stored within the pointer.

Examples

use crossbeam_epoch::Owned;

assert_eq!(Owned::new(1234).tag(), 0);
fn with_tag(self, tag: usize) -> Owned<T>

Returns the same pointer, but tagged with tag. tag is truncated to be fit into the unused bits of the pointer to T.

Examples

use crossbeam_epoch::Owned;

let o = Owned::new(0u64);
assert_eq!(o.tag(), 0);
let o = o.with_tag(2);
assert_eq!(o.tag(), 2);

Trait Implementations

impl<T> From<Box<T>> for Owned<T>

fn from(b: Box<T>) -> Self

Returns a new owned pointer pointing to b.

Panics

Panics if the pointer (the Box) is not properly aligned.

Examples

use crossbeam_epoch::Owned;

let o = unsafe { Owned::from_raw(Box::into_raw(Box::new(1234))) };

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) -> usize
unsafe fn from_usize(data: usize) -> Self

Returns 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) -> T

Returns 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) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> ToOwned for Owned<T> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Owned<T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses 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>