pub struct UpVal {
pub state: RefCell<UpValState>,
/* 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.
Canonical state lives in two Cell fields (the tag and the open payload)
plus a Cell<LuaValue> holding the closed payload. The state
RefCell<UpValState> mirror is kept for cold consumers that still call
slot() to inspect the open/closed shape. Scalar-to-scalar closed writes
may leave the mirror’s scalar payload stale; callers that need the current
closed value must use closed_value / try_closed_value. The split lets
state.rs::upvalue_get / upvalue_set short-circuit the Open path with
zero RefCell borrow overhead, which is the dominant cost in
fibonacci-class recursion benchmarks.
Fields§
§state: RefCell<UpValState>Implementations§
Source§impl UpVal
impl UpVal
pub fn open(thread_id: usize, idx: StackIdx) -> UpVal
pub fn closed(v: LuaValue) -> UpVal
Sourcepub fn slot(&self) -> Ref<'_, UpValState>
pub fn slot(&self) -> Ref<'_, UpValState>
Backwards-compat handle on the full UpValState. Out-of-crate code
matches against this through Ref::deref. Hot-path callers should
use try_open_payload / closed_value instead.
pub fn is_open(&self) -> bool
pub fn is_closed(&self) -> bool
Sourcepub fn try_open_payload(&self) -> Option<(usize, StackIdx)>
pub fn try_open_payload(&self) -> Option<(usize, StackIdx)>
Zero-RefCell fast path used by upvalue_get / upvalue_set.
Returns Some((thread_id, idx)) when the upvalue is still open,
None otherwise.
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).
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>().