Struct Owned

struct Owned<T: ?Sized + Pointable> { ... }

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: 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 as >::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: 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: &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: 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);

impl<P, T> Receiver for Owned<T>

impl<T> Any for Owned<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Owned<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Owned<T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Owned<T>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> Freeze for Owned<T>

impl<T> From for Owned<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From for Owned<T>

fn from(t: T) -> Self

impl<T> From 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 for Owned<T>

fn from(t: never) -> T

impl<T> Pointable for Owned<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> RefUnwindSafe for Owned<T>

impl<T> Send for Owned<T>

impl<T> Sync for Owned<T>

impl<T> ToOwned for Owned<T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> Unpin for Owned<T>

impl<T> UnsafeUnpin for Owned<T>

impl<T> UnwindSafe for Owned<T>

impl<T, U> Into for Owned<T>

fn into(self: 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 for Owned<T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Owned<T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

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

fn as_mut(self: &mut Self) -> &mut T

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

fn as_ref(self: &Self) -> &T

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

fn borrow(self: &Self) -> &T

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

fn borrow_mut(self: &mut Self) -> &mut T

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

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

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

fn deref(self: &Self) -> &T

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

fn deref_mut(self: &mut Self) -> &mut T

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

fn drop(self: &mut Self)

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

fn into_usize(self: 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) -> Self