Skip to main content

Input

Trait Input 

Source
pub trait Input: Send + Sync {
    // Required method
    fn read(&mut self, buffer: &mut [u8]) -> Result<usize, InputError>;

    // Provided methods
    fn read_to_end(&mut self, out: &mut Vec<u8>) -> Result<(), InputError> { ... }
    fn read_line(&mut self, line: &mut String) -> Result<bool, InputError> { ... }
}
Expand description

A readable byte stream.

The Engine only knows about bytes; line orientation (if any) is a property of the stream’s source.

Required Methods§

Source

fn read(&mut self, buffer: &mut [u8]) -> Result<usize, InputError>

Reads bytes into buffer; returns the number of bytes read.

Returns Ok(0) at end of stream. Implementations may return fewer bytes than the buffer’s length.

Provided Methods§

Source

fn read_to_end(&mut self, out: &mut Vec<u8>) -> Result<(), InputError>

Reads until end of stream, appending everything to out.

Source

fn read_line(&mut self, line: &mut String) -> Result<bool, InputError>

Reads a line (terminated by \n), appending it to line.

The trailing newline is included. Returns Ok(false) when the stream is exhausted before any byte was read. Bytes are buffered to the newline and decoded once, so multi-byte UTF-8 sequences survive; bytes that are not valid UTF-8 are replaced with the Unicode replacement character.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§