Struct scc::ebr::Arc

source · []
pub struct Arc<T: 'static> { /* private fields */ }
Expand description

Arc is a reference-counted handle to an instance.

Implementations

Creates a new instance of Arc.

Examples
use scc::ebr::Arc;

let arc: Arc<usize> = Arc::new(31);

Generates a Ptr out of the Arc.

Examples
use scc::ebr::{Arc, Barrier};

let arc: Arc<usize> = Arc::new(37);
let barrier = Barrier::new();
let ptr = arc.ptr(&barrier);
assert_eq!(*ptr.as_ref().unwrap(), 37);

Returns a mutable reference to the underlying instance if the instance is exclusively owned.

Safety

If there is no Ptr to the underlying instance, it is safe.

Examples
use scc::ebr::Arc;

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

Provides a raw pointer to the underlying instance.

Examples
use scc::ebr::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Relaxed;

let arc: Arc<usize> = Arc::new(10);
let arc_cloned: Arc<usize> = arc.clone();

assert_eq!(arc.as_ptr(), arc_cloned.as_ptr());
assert_eq!(unsafe { *arc.as_ptr() }, unsafe { *arc_cloned.as_ptr() });

Drops the underlying instance if the last reference is dropped.

The instance is not passed to the garbage collector when the last reference is dropped, instead the method drops the instance immediately. The semantics is the same as that of std::sync::Arc.

Safety

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

Examples
use scc::ebr::Arc;
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 arc: Arc<T> = Arc::new(T(&DROPPED));

unsafe {
    arc.drop_in_place();
}
assert!(DROPPED.load(Relaxed));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Executes the destructor for this type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.