Skip to main content

ZIO

Struct ZIO 

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

Buffered input stream wrapping an external chunk-reader callback.

Corresponds to struct Zio / ZIO in lzio.h. The C struct stored a lua_State *L back-pointer and a void *data opaque pointer alongside a raw lua_Reader function pointer. In Rust:

  • lua_State *L is removed from the struct; callers hold &mut LuaState directly and pass it to fallible methods.
  • void *data is folded into the reader closure.
  • const char *p (raw pointer into the reader’s internal buffer) becomes a usize index into the owned current_chunk field.

Implementations§

Source§

impl ZIO

Source

pub fn new(reader: ChunkReader) -> Self

Initialise a ZIO with the given reentrant reader callback.

Corresponds to luaZ_init in lzio.c. The C parameters reader and data are combined into a single closure; L is threaded through the fallible methods rather than stored on the struct.

Source

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

Construct a ZIO that yields the supplied bytes once and then EOZ.

Used for in-memory sources (a string chunk, or the lexer’s own unit tests) where there is no reader to call back into Lua. The state passed to getc/fill is ignored by this reader.

Source

pub fn take(&mut self) -> ZIO

Move this stream out, leaving an exhausted (empty) ZIO in its place.

The parser owns the lexer’s LexState, which owns its ZIO; the loader only holds a &mut ZIO. This hands the live stream — its reader and any bytes already buffered by [getc] — to the parser by value so the lexer can keep pulling from the same reader (and the same &mut LuaState) on demand. The original slot becomes an immediately-EOZ stream.

Source

pub fn getc(&mut self, state: &mut LuaState) -> Result<i32, LuaError>

Return the next byte from the stream as an i32, or [EOZ] at end-of-stream.

This is the hot-path inline method corresponding to the zgetc macro. When bytes remain in the current chunk no allocation occurs.

C’s macro uses (z)->n-- > 0, which reads n, tests it, then decrements; when n == 0 the test is false (0 > 0) so fill is called without decrementing. This preserves that: if self.n > 0 followed by an explicit self.n -= 1.

Auto Trait Implementations§

§

impl !RefUnwindSafe for ZIO

§

impl !Send for ZIO

§

impl !Sync for ZIO

§

impl !UnwindSafe for ZIO

§

impl Freeze for ZIO

§

impl Unpin for ZIO

§

impl UnsafeUnpin for ZIO

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.