SendWrapper
This Rust crate implements a wrapper type called SendWrapper which allows you to move around non-Send types
between threads, as long as you access the contained value only from within the original thread. You also have to
make sure that the wrapper is dropped from within the original thread. If any of these constraints is violated,
a panic occurs.
Examples
use SendWrapper;
use Rc;
use thread;
use channel;
// Rc is a non-Send type.
let value = new;
// We now wrap the value with `SendWrapper` (value is moved inside).
let wrapped_value = new;
// A channel allows us to move the wrapped value between threads.
let = channel;
let t = spawn;
let wrapped_value = receiver.recv.unwrap;
// Now you can use the value again.
let value = wrapped_value.get.unwrap;
// alternatives for mutable dereferencing (value and wrapped_value must be mutable too, then):
// let mut value = wrapped_value.get_mut().unwrap();
Wrapping Futures and Streams
To use SendWrapper on Futures or Streams, you should enable the Cargo feature futures first:
= { = "0.7", = ["futures"] }
Then, you can transparently wrap your Future or Stream:
use ;
use SendWrapper;
// `Rc` is a `!Send` type,
let value = new;
// so this `Future` is `!Send` too as increments `Rc`'s inner counter.
let future = lazy;
// We now wrap the `future` with `SendWrapper` (value is moved inside),
let wrapped_future = new;
// so now it's `Send` + `Sync` (`BoxFuture` trait object contains `Send` requirement).
let boxed_future: = Boxpin;
let t = spawn;
Changelog
See CHANGELOG.md
License
compio-send-wrapper is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE, and LICENSE-MIT for details.