pub fn with_encapsulated<'env, E, F, T>(data: E, f: F) -> TExpand description
Create a scope for sending references to another thread.
Encapsulate one or more references from data inside of Capsule or CapsuleMut which can
be safely passed to another thread (for example, through a channel). The f function is then
called with the capsule(s), and then this function will wait until all created capsules have
been dropped, even if they are eventually dropped by another thread.
Note that this function will block unless the capsules are dropped by f on the same thread.
data is any type that implements the Encapsulate trait. The most significant
implementations of this trait includes:
&Twhich is convertend into aCapsule<T>&mut Twhich is converted into aCapsuleMut<T>- A tuple of up to 8 elements, each of which implements
Encapsulate, which is converted into a tuple where each item is converted into the respectiveEncapsulatedtype. [T; N]where T implementsEncapsulate.encapsulate::Genwhich will allow you to directly use theScopeto convert references to capsules inside a function or (more likely) closure.