[][src]Trait maybe_sync::MaybeSync

pub trait MaybeSync { }

Marker trait that can represent nothing if feature "sync" is not enabled. Or be reexport of std::marker::Sync if "sync" feature is enabled.

It is intended to be used as trait bound where std::marker::Sync bound is required only when application is compiled for multithreaded environment.
If "sync" feature is not enabled then this trait bound will NOT allow reference to the value to cross thread boundary or be used where sync value is expected.

Examples


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

#[cfg(not(feature = "sync"))]
{
  // If this code is compiled then `MaybeSync` dummy markerd implemented for all types.
  maybe_shares(Arc::new(Cell::new(42)));
}

Implementors

impl<T> MaybeSync for T where
    T: ?Sized
[src]

All values are maybe sync.

Loading content...