Skip to main content

LuaStringImpl

Struct LuaStringImpl 

Source
pub struct LuaStringImpl { /* private fields */ }
Expand description

A Lua string: an immutable, reference-counted byte sequence.

Short strings (<= MAX_SHORT_LEN = 40 bytes) are interned in the StringPool on GlobalState; two short strings with the same bytes are guaranteed to be the same GcRef (pointer equality via Rc::ptr_eq).

Long strings are heap-allocated independently and never interned. Their hash is computed lazily on first call to [hash_long_str] and cached via interior mutability (Cell<u32>).

§C mapping (types.tsv)

TString             → LuaStringImpl
TString.extra       → extra: Cell<u8>   (reserved-word idx for Short; hash-ready flag for Long)
TString.shrlen      → kind: StringKind   (0xFF sentinel replaced by enum variant)
TString.hash        → hash: Cell<u32>
TString.u.lnglen    → bytes.len()        (length implicit in Rc<[u8]>)
TString.u.hnext     → (removed)          (intrusive chain gone; StringPool uses HashMap)
TString.contents    → bytes: Rc<[u8]>

Implementations§

Source§

impl LuaStringImpl

Source

pub fn as_bytes(&self) -> &[u8]

Returns the string’s bytes.

macros.tsv: getstr / getlngstr / getshrstrts.as_bytes()

Source

pub fn len(&self) -> usize

Returns the byte length of the string.

for Long. In Rust both cases are bytes.len(). macros.tsv: tsslents.len()

Source

pub fn is_long(&self) -> bool

Returns true if this is a long (non-interned) string.

Source

pub fn is_short(&self) -> bool

Returns true if this is a short (interned) string.

Source

pub fn is_reserved_word(&self) -> bool

Returns true if this short string is a Lua reserved word.

macros.tsv: isreservedts.is_reserved_word()

Source

pub fn is_white(&self) -> bool

GC color predicate. Returns true if this object is “white” (unreachable) in the GC’s current wave.

macros.tsv: iswhiteobj.is_white()

PORT NOTE: GC color management is deferred to Phase D. In Phases A–C all objects are reachable via Rc reference counts and this always returns false (nothing is white / unreachable).

Source

pub fn flip_white(&self)

Flip GC color from white to the current non-white (resurrect a dead object).

macros.tsv: changewhiteobj.flip_white()

PORT NOTE: GC color management deferred to Phase D; no-op in Phases A–C.

Trait Implementations§

Source§

impl PartialEq for LuaStringImpl

Source§

fn eq(&self, other: &Self) -> bool

Equality for Lua strings.

For short strings (interned), pointer equality via Rc::ptr_eq is sufficient and matches eqshrstr in C. For long strings, we fall back to byte comparison, matching luaS_eqlngstr in C.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Trace for LuaStringImpl

Phase-B internal richer LuaString. The byte buffer is a Rust Rc<[u8]> (not GC-managed); no fields to mark.

Source§

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

Source§

impl Eq for LuaStringImpl

Auto Trait Implementations§

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.