[][src]Trait maybe_sync::MaybeSend

pub trait MaybeSend { }

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

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

Examples


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

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

Implementors

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

All values are maybe sendable.

Loading content...