sdd

Struct Owned

Source
pub struct Owned<T> { /* private fields */ }
Expand description

Owned uniquely owns an instance.

The instance it passed to the EBR garbage collector when the Owned is dropped.

Implementations§

Source§

impl<T: 'static> Owned<T>

Source

pub fn new(t: T) -> Self

Creates a new instance of Owned.

The type of the instance must be determined at compile-time, must not contain non-static references, and must not be a non-static reference since the instance can, theoretically, survive the process. For instance, struct Disallowed<'l, T>(&'l T) is not allowed, because an instance of the type cannot outlive 'l whereas the garbage collector does not guarantee that the instance is dropped within 'l.

§Examples
use sdd::Owned;

let owned: Owned<usize> = Owned::new(31);
Source§

impl<T> Owned<T>

Source

pub unsafe fn new_unchecked(t: T) -> Self

Creates a new Owned without checking the lifetime of T.

§Safety

T::drop can be run after the Owned is dropped, therefore it is safe only if T::drop does not access short-lived data or std::mem::needs_drop is false for T.

§Examples
use sdd::Owned;

let hello = String::from("hello");
let owned: Owned<&str> = unsafe { Owned::new_unchecked(hello.as_str()) };
Source

pub fn get_guarded_ptr<'g>(&self, _guard: &'g Guard) -> Ptr<'g, T>

Returns a Ptr to the instance that may live as long as the supplied Guard.

§Examples
use sdd::{Guard, Owned};

let owned: Owned<usize> = Owned::new(37);
let guard = Guard::new();
let ptr = owned.get_guarded_ptr(&guard);
drop(owned);

assert_eq!(*ptr.as_ref().unwrap(), 37);
Source

pub fn get_guarded_ref<'g>(&self, _guard: &'g Guard) -> &'g T

Returns a reference to the instance that may live as long as the supplied Guard.

§Examples
use sdd::{Guard, Owned};

let owned: Owned<usize> = Owned::new(37);
let guard = Guard::new();
let ref_b = owned.get_guarded_ref(&guard);
drop(owned);

assert_eq!(*ref_b, 37);
Source

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

Returns a mutable reference to the instance.

§Safety

The method is unsafe since there can be a Ptr to the instance.

§Examples
use sdd::Owned;

let mut owned: Owned<usize> = Owned::new(38);
unsafe {
    *owned.get_mut() += 1;
}
assert_eq!(*owned, 39);
Source

pub fn as_ptr(&self) -> *const T

Provides a raw pointer to the instance.

§Examples
use sdd::Owned;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Relaxed;

let owned: Owned<usize> = Owned::new(10);

assert_eq!(unsafe { *owned.as_ptr() }, 10);
Source

pub unsafe fn drop_in_place(self)

Drops the instance immediately.

§Safety

The caller must ensure that there is no Ptr pointing to the instance.

§Examples
use sdd::Owned;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Relaxed;

static DROPPED: AtomicBool = AtomicBool::new(false);
struct T(&'static AtomicBool);
impl Drop for T {
    fn drop(&mut self) {
        self.0.store(true, Relaxed);
    }
}

let owned: Owned<T> = Owned::new(T(&DROPPED));
assert!(!DROPPED.load(Relaxed));

unsafe {
    owned.drop_in_place();
}

assert!(DROPPED.load(Relaxed));

Trait Implementations§

Source§

impl<T> AsRef<T> for Owned<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Debug> Debug for Owned<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for Owned<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T> Drop for Owned<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send> Send for Owned<T>

Source§

impl<T: Sync> Sync for Owned<T>

Source§

impl<T: UnwindSafe> UnwindSafe for Owned<T>

Auto Trait Implementations§

§

impl<T> Freeze for Owned<T>

§

impl<T> RefUnwindSafe for Owned<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Owned<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.