Type Alias Rc

Source
pub type Rc<T> = Rc<T>;
Available on crate feature alloc only.
Expand description

A pointer type which can be safely shared between threads when “sync” feature is enabled.
A pointer type which can be shared, but only within single thread where it was created when “sync” feature is not enabled.

§Example


fn maybe_sends<T: MaybeSend + Debug + 'static>(val: T) {
  #[cfg(feature = "sync")]
  {
    // If this code is compiled then `MaybeSend` is alias to `std::marker::Send`.
    std::thread::spawn(move || { println!("{:?}", val) });
  }
}

// Unlike `std::rc::Rc` this `maybe_sync::Rc<T>` would always
// satisfy `MaybeSend` bound when `T: MaybeSend + MaybeSync`,
// even if feature "sync" is enabeld.
maybe_sends(Rc::new(42));

Aliased Type§

pub struct Rc<T> { /* private fields */ }