Struct diplomatic_bag::BaggageHandler
source · [−]pub struct BaggageHandler(_);
Expand description
A type that allows wrapping and unwrapping DiplomaticBag
s inside the
execution context of another bag.
This allows computations on the wrapped values of multiple bags, and
provides a mechanism for returning !Send
and !Sync
types from
computations done on values inside bags.
Examples
let one = DiplomaticBag::new(|_handler| 1);
let two = DiplomaticBag::new(|_handler| 2);
let three = one.and_then(|handler, one| {
let three = one + handler.unwrap(two.as_ref());
handler.wrap(three)
});
Implementations
sourceimpl BaggageHandler
impl BaggageHandler
sourcepub fn wrap<T>(&self, value: T) -> DiplomaticBag<T>
pub fn wrap<T>(&self, value: T) -> DiplomaticBag<T>
Wrap a value in a DiplomaticBag
, allowing it to be sent to other
threads even if it is not Send
.
Examples
let foo: DiplomaticBag<u8> = DiplomaticBag::new(|_handler| 2);
let bar: DiplomaticBag<u8> =
foo.and_then(|handler, value| handler.wrap(value.clone()));
sourcepub fn unwrap<T>(&self, proxy: DiplomaticBag<T>) -> T
pub fn unwrap<T>(&self, proxy: DiplomaticBag<T>) -> T
Unwrap a value in a DiplomaticBag
, allowing it to be used inside
the execution context of another bag.
Examples
let one = DiplomaticBag::new(|_handler| 1);
let two = DiplomaticBag::new(|_handler| 2);
let three = one.and_then(|handler, one| one + handler.unwrap(two));
Trait Implementations
sourceimpl Clone for BaggageHandler
impl Clone for BaggageHandler
sourcefn clone(&self) -> BaggageHandler
fn clone(&self) -> BaggageHandler
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for BaggageHandler
impl Debug for BaggageHandler
impl Copy for BaggageHandler
Auto Trait Implementations
impl RefUnwindSafe for BaggageHandler
impl !Send for BaggageHandler
impl !Sync for BaggageHandler
impl Unpin for BaggageHandler
impl UnwindSafe for BaggageHandler
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more