Skip to main content

LuaFileHandle

Trait LuaFileHandle 

Source
pub trait LuaFileHandle: Send {
    // Required methods
    fn read_byte(&mut self) -> i32;
    fn unread_byte(&mut self, byte: i32);
    fn write_bytes(&mut self, data: &[u8]) -> Result<usize, Error>;
    fn flush(&mut self) -> Result<(), Error>;
    fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>;
    fn tell(&mut self) -> Result<u64, Error>;
    fn clear_error(&mut self);
    fn has_error(&self) -> bool;

    // Provided methods
    fn last_error_info(&self) -> Option<(i32, String)> { ... }
    fn set_buf_mode(&mut self, _mode: i32, _size: usize) -> Result<(), Error> { ... }
}
Expand description

Capabilities required by the io library from an OS file handle.

Designed to be object-safe (Box<dyn LuaFileHandle>). Implementations backed by std::fs::File live in lua-cli; implementations for the standard streams live in lua-stdlib/src/io_lib.rs.

Required Methods§

Source

fn read_byte(&mut self) -> i32

Read one byte from the handle; return it as i32, or -1 on EOF/error.

Source

fn unread_byte(&mut self, byte: i32)

Push back a previously-read byte so the next read_byte returns it.

Source

fn write_bytes(&mut self, data: &[u8]) -> Result<usize, Error>

Write a byte slice; return the number of bytes actually written.

Source

fn flush(&mut self) -> Result<(), Error>

Flush any write buffers to the underlying OS handle.

Source

fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>

Seek within the file.

Source

fn tell(&mut self) -> Result<u64, Error>

Return the current file position without moving it.

Source

fn clear_error(&mut self)

Clear the error/EOF flag on the handle.

Source

fn has_error(&self) -> bool

Return true if the handle has a pending error.

Provided Methods§

Source

fn last_error_info(&self) -> Option<(i32, String)>

Return the last pending OS error as (errno, message) when available.

Some real Lua programs probe platform behavior through specific errno values. LuaRocks’ macOS directory detection, for example, expects reading an opened directory to report EISDIR rather than look like EOF.

Source

fn set_buf_mode(&mut self, _mode: i32, _size: usize) -> Result<(), Error>

Control write buffering. Mode values mirror file:setvbuf option order: 0 = no buffering, 1 = full buffering, 2 = line buffering.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§