Skip to main content

LexBuffer

Struct LexBuffer 

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

Growable byte buffer used by the lexer for token text accumulation.

Corresponds to Mbuffer in lzio.h. The C struct tracked buffer, n (used length), and buffsize (allocated capacity) as three separate fields with manual realloc. In Rust all three are implicit in Vec<u8>.

§C mapping (types.tsv)

Mbuffer     → LexBuffer
.buffer     → Vec<u8>   (heap storage)
.n          → Vec::len()
.buffsize   → Vec::capacity()

Implementations§

Source§

impl LexBuffer

Source

pub fn new() -> Self

Construct an empty LexBuffer. Corresponds to the luaZ_initbuffer macro.

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Return the buffer contents as a mutable byte slice.

Source

pub fn capacity(&self) -> usize

Return the buffer’s current allocation capacity in bytes.

Source

pub fn len(&self) -> usize

Return the number of valid bytes currently stored in the buffer.

Source

pub fn truncate_by(&mut self, i: usize)

Shorten the live contents by i bytes without releasing capacity.

Source

pub fn clear(&mut self)

Reset the live length to zero without releasing capacity.

Source

pub fn resize( &mut self, _state: &mut LuaState, size: usize, ) -> Result<(), LuaError>

Resize the buffer to exactly size bytes, filling new bytes with 0.

Returns Err(LuaError::Memory) on allocation failure.

PORT NOTE: the C macro routes through luaM_reallocvchar and Lua’s custom allocator. Phase A uses Vec::resize with Rust’s global allocator; OOM propagation via the custom allocator is a Phase D concern.

Trait Implementations§

Source§

impl Default for LexBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.