Skip to main content

IoContext

Struct IoContext 

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

File descriptor table for the REPL session.

Lives in the binary layer and is passed into eval_with_io. File descriptors 1 (stdout) and 2 (stderr) are virtual — not stored here, handled by write_to_fd directly. User-opened files start at fd 3.

Implementations§

Source§

impl IoContext

Source

pub fn new() -> Self

Creates an empty I/O context with no open file handles.

Source

pub fn fopen(&mut self, path: &str, mode: &str) -> i32

Opens a file and returns a new file descriptor, or -1 on failure. Supported modes: "r", "w", "a", "r+".

Source

pub fn fclose(&mut self, fd: i32) -> i32

Closes a file descriptor. Returns 0 on success, -1 if fd is unknown.

Source

pub fn fclose_all(&mut self)

Closes all open file handles.

Source

pub fn fgetl(&mut self, fd: i32) -> Option<String>

Reads one line from fd, stripping the trailing newline (fgetl semantics). Returns None at EOF or on error.

Source

pub fn fgets(&mut self, fd: i32) -> Option<String>

Reads one line from fd, keeping the trailing newline (fgets semantics). Returns None at EOF or on error.

Source

pub fn write_to_fd(&mut self, fd: i32, s: &str) -> Result<(), String>

Writes a string to a file descriptor. fd 1 = stdout, fd 2 = stderr; all others must be in the handle table.

Trait Implementations§

Source§

impl Default for IoContext

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V