Expand description
Explicit stack slots, which can be used for stack emplacement.
A Slot
is uninitialized storage on the stack that can be manipulated
explicitly. Notionally, a Slot<T>
represents a let x: T;
in some
function’s stack.
Slot
s mut be created with the slot!()
macro:
slot!(storage);
let mut x = storage.put(42);
*x /= 2;
assert_eq!(*x, 21);
Unfortunately, due to the constrains of Rust today, it is not possible to
produce a Slot
as part of a larger expression; since it needs to expand
to a let
to bind the stack location, slot!()
must be a statement, not
an expression.
Slot
s can also be used to implement a sort of “guaranteed RVO”:
fn returns_on_the_stack(val: i32, storage: Slot<i32>) -> Option<MoveRef<i32>> {
if val == 0 {
return None
}
Some(storage.put(val))
}
slot!(storage);
let val = returns_on_the_stack(42, storage);
assert_eq!(*val.unwrap(), 42);
Slot
s provide a natural location for emplacing values on the stack.
The moveit!()
macro is intended to make this operation
straight-forward.
§DroppingSlot
DroppingSlot
is a support type similar to Slot
that is used for
implementing DerefMove
, but which users should otherwise not construct
themselves (despite it being otherwise perfectly safe to do so).
Structs§
- Similar to a
Slot
, but able to drop its contents. - An empty slot on the stack into which a value could be emplaced.