Struct Delegate
pub struct Delegate<T> { /* private fields */ }
Expand description
Delegate
or lend an object to another task.
This struct can be used to lend a &mut T
to another task on the same executor.
The other task can then call a closure on it. After that, the &mut T
is returned
to the original task.
Under the hood, Delegate
leverages [SendCell
] to ensure the delegated
object stays on the same executor.
Example:
static SOME_VALUE: Delegate<u32> = Delegate::new();
// in some task
async fn foo() {
let mut my_val = 0u32;
SOME_VALUE.lend(&mut my_val).await;
assert_eq!(my_val, 1);
}
// in some other task
async fn bar() {
SOME_VALUE.with(|val| *val = 1).await;
}
TODO: this is a PoC implementation.
Implementations§
§impl<T> Delegate<T>
impl<T> Delegate<T>
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Delegate<T>
impl<T> !RefUnwindSafe for Delegate<T>
impl<T> Send for Delegate<T>
impl<T> Sync for Delegate<T>
impl<T> Unpin for Delegate<T>
impl<T> UnwindSafe for Delegate<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more