Skip to main content

LuaString

Struct LuaString 

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

Lua’s immutable byte-string value.

The byte payload is a Box<[u8]>, NOT an Rc<[u8]>. Strings are immutable and GC-owned: every live LuaString is reached through a GcRef<LuaString> (the interner stores GcRefs, LuaValue::Str holds a GcRef), and all value-level sharing happens at that GcRef layer. An Rc<[u8]> would co-locate a 16-byte refcount header (strong + weak counts) with the payload in the string’s heap allocation, so every string allocation paid those 16 bytes on top of its GcBox<LuaString> for a refcount machinery nothing uses. Switching to Box<[u8]> drops the 16-byte header per string and the refcount inc/dec traffic; the win is in the heap allocation, not the struct field (both Rc<[u8]> and Box<[u8]> are 16-byte fat pointers).

The #[derive(Clone)] is retained, but a by-value LuaString clone is now a deep copy (alloc + memcpy) rather than a refcount bump. This is acceptable because no hot path clones a LuaString by value — hot sharing goes through the Copy GcRef<LuaString> handle. The only by-value clones are cold (error-message construction, GlobalState init).

Implementations§

Source§

impl LuaString

Source

pub fn from_bytes(b: Vec<u8>) -> Self

Source

pub fn from_slice(b: &[u8]) -> Self

Construct directly from a borrowed slice with a single allocating copy.

from_bytes takes an owned Vec<u8>, but Vec<u8> -> Box<[u8]> via into_boxed_slice only adopts the existing buffer when it is exactly full, otherwise it reallocates; a caller holding only a slice would copy twice (once into a Vec, once into the Box). Box::from(&[u8]) copies the slice straight into the final allocation, matching C’s single luaS_newlstr allocation per string. Hash is computed with the same algorithm as from_bytes.

Source

pub fn placeholder() -> Self

Source

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

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_short(&self) -> bool

Source

pub fn is_long(&self) -> bool

Source

pub fn hash(&self) -> u32

Source

pub fn buffer_bytes(&self) -> usize

Source

pub fn is_reserved_word(&self) -> bool

Source

pub fn hash_bytes(bytes: &[u8], seed: u32) -> u32

Source

pub fn hash_long(&mut self) -> u32

Trait Implementations§

Source§

impl Clone for LuaString

Source§

fn clone(&self) -> LuaString

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LuaString

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for LuaString

Source§

impl PartialEq for LuaString

Source§

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

Tests for self and other values to be equal, and is used by ==.
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 LuaString

LuaString — interned byte string. The Rc<[u8]> backing buffer is owned, not GC-managed, so this impl is intentionally empty.

Source§

fn type_name(&self) -> &'static str

Concrete Rust type name for diagnostic/testC telemetry (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>().
Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.