pub struct Arc<T: 'static> { /* private fields */ }
Expand description
Arc
is a reference-counted handle to an instance.
Implementations
sourceimpl<T: 'static> Arc<T>
impl<T: 'static> Arc<T>
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
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() });
sourcepub unsafe fn drop_in_place(self)
pub unsafe fn drop_in_place(self)
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
impl<T: 'static + Send> Send for Arc<T>
impl<T: 'static + Sync> Sync for Arc<T>
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more