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>;
    fn flush(&mut self) -> Result<()>;
    fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
    fn tell(&mut self) -> Result<u64>;
    fn clear_error(&mut self);
    fn has_error(&self) -> bool;

    // Provided method
    fn set_buf_mode(&mut self, _mode: i32, _size: usize) -> Result<()> { ... }
}
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>

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

Source

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

Flush any write buffers to the underlying OS handle.

Source

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

Seek within the file.

Source

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

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 set_buf_mode(&mut self, _mode: i32, _size: usize) -> Result<()>

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§