[][src]Type Definition maybe_sync::Rc

type Rc<T> = Rc<T>;
This is supported on feature="alloc" only.

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));