Macro moveit::slot

source ·
macro_rules! slot {
    () => { ... };
    (#[dropping]) => { ... };
    ($($name:ident $(: $ty:ty)?),* $(,)*) => { ... };
    (#[dropping] $($name:ident $(: $ty:ty)?),* $(,)*) => { ... };
    (@tyof) => { ... };
    (@tyof $ty:ty) => { ... };
}
Expand description

Constructs a new Slot.

Because Slots need to own data on the stack, but that data cannot move with the Slot, it must be constructed using this macro. For example:

moveit::slot!(x, y: bool);
let x = x.put(5);
let y = y.put(false);

This macro is especially useful for passing data into functions that want to emplace a value into the caller.

The slot!(#[dropping] x) syntax can be used to create a DroppingSlot instead. This should be a comparatively rare operation.

This macro can also be used without arguments to create a temporary Slot. Such types cannot be assigned to variables but can be used as part of a larger expression:

let bad: Slot<i32> = moveit::slot!();
bad.put(4);  // Borrow check error.
fn do_thing(x: Slot<i32>) { /* ... */ }
do_thing(moveit::slot!())