pub struct UpVal { /* private fields */ }Expand description
A closure upvalue. Open upvalues point at a slot on a thread’s stack (referred to by index, since the stack reallocates). Closed upvalues own the value.
State lives entirely in one Cell<UpValState> and is
single-source-of-truth. Closing is terminal — there is no re-open path — so
the state never reverts from Closed back to Open.
Read the open shape with try_open_payload
(None once closed) and the closed payload with
closed_value / try_closed_value.
The Cell layout lets state.rs::upvalue_get / upvalue_set short-circuit
the Open path with zero borrow-guard overhead, which is the dominant cost in
fibonacci-class recursion benchmarks.
Implementations§
Source§impl UpVal
impl UpVal
pub fn open(thread_id: u64, idx: StackIdx) -> Self
pub fn closed(v: LuaValue) -> Self
pub fn is_open(&self) -> bool
pub fn is_closed(&self) -> bool
Sourcepub fn try_open_payload(&self) -> Option<(u64, StackIdx)>
pub fn try_open_payload(&self) -> Option<(u64, StackIdx)>
Zero-overhead read of the open shape used by upvalue_get /
upvalue_set and every out-of-crate consumer that inspects an open
upvalue’s (thread_id, idx). Returns Some((thread_id, idx)) when the
upvalue is still open, None once it has been closed. thread_id is a
u64 end-to-end so the never-reused monotonic id domain is preserved on
every target, including 32-bit usize ones (wasm32).
Sourcepub fn closed_value(&self) -> LuaValue
pub fn closed_value(&self) -> LuaValue
Returns the closed-side value. Callers must have confirmed the
upvalue is closed (try_open_payload returned None); an open upvalue
reports LuaValue::Nil, matching the value its closed slot held under
the previous layout.
pub fn close_with(&self, v: LuaValue)
pub fn set_closed_value(&self, v: LuaValue)
pub fn try_closed_value(&self) -> Option<LuaValue>
Trait Implementations§
Source§impl Trace for UpVal
UpVal — Open (refers to a thread stack slot by index) or Closed (owns a
LuaValue). The Open variant carries no direct GC reference; the slot it
points at is traced through the owning thread’s stack walk.
impl Trace for UpVal
UpVal — Open (refers to a thread stack slot by index) or Closed (owns a LuaValue). The Open variant carries no direct GC reference; the slot it points at is traced through the owning thread’s stack walk.
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Heap::type_name_count). Collector behavior must not branch on
this. The default covers container blanket impls, which are never
GC-boxed directly; concrete runtime types override it with
std::any::type_name::<Self>().