Type Definition hybrid_rc::Arc[][src]

pub type Arc<T> = HybridRc<T, Shared>;
Expand description

Type alias for a shared reference counting pointer.

Provided to ease migrating from std::sync::Arc.

See the module-level documentation for more details.

The inherent methods of Arc are all associated functions, which means that you have to call them as e.g. Arc::to_local(&x) instead of x.to_local(). This avoids conflicts with methods of the inner type T.

Implementations

Creates a new local reference (Rc) for the referenced value.

Returns None if at least one Rc already exists on another thread.

Example
use hybrid_rc::{Rc, Arc};

let local = Rc::new(42i32);
let shared = Rc::to_shared(&local);

// `shared` can be safely transferred to another thread
std::thread::spawn(move || assert_eq!(*shared, 42i32)).join()?;

Creates a new Arc<T>, moving data into a reference counted allocation.

Initially the shared value has no owner thread, so any thread may call to_local() to assume ownership.

Only useful for types that are Sync + Send, as otherwise the Arc can’t be sent to other threads.

Example
use hybrid_rc::Arc;

let arc = Arc::new(42i32);

std::thread::spawn(move || assert!(*arc == 42)).join()?;