Skip to main content

UpVal

Struct UpVal 

Source
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 RefCell<LuaValue> holding the closed payload. The state RefCell<UpValState> mirror is kept consistent so cold consumers that still call slot() see the correct view. 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

Source

pub fn open(thread_id: usize, idx: StackIdx) -> Self

Source

pub fn closed(v: LuaValue) -> Self

Source

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.

Source

pub fn is_open(&self) -> bool

Source

pub fn is_closed(&self) -> bool

Source

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.

Source

pub fn closed_value(&self) -> Ref<'_, LuaValue>

Borrows the closed-side value. Callers must have confirmed the upvalue is closed (try_open_payload returned None).

Source

pub fn close_with(&self, v: LuaValue)

Source

pub fn set_closed_value(&self, v: LuaValue)

Source

pub fn try_closed_value(&self) -> Option<Ref<'_, LuaValue>>

Trait Implementations§

Source§

impl Debug for UpVal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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.

Source§

fn trace(&self, m: &mut Marker)

Auto Trait Implementations§

§

impl !Freeze for UpVal

§

impl !RefUnwindSafe for UpVal

§

impl !Send for UpVal

§

impl !Sync for UpVal

§

impl Unpin for UpVal

§

impl UnsafeUnpin for UpVal

§

impl !UnwindSafe for UpVal

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.