Trait infinite_rs::common::extensions::BufReaderExt
source · pub trait BufReaderExt: BufReadwhere
Self: Seek,{
// Provided methods
fn read_cstring(&mut self) -> Result<String> { ... }
fn read_fixed_string(&mut self, length: usize) -> Result<String> { ... }
fn read_enumerable<T: Default + Readable>(
&mut self,
count: usize,
) -> Result<Vec<T>>
where Self: Sized,
Vec<T>: FromIterator<T> { ... }
}Expand description
Extension trait for BufReader to add custom reading methods.
Provided Methods§
sourcefn read_cstring(&mut self) -> Result<String>
fn read_cstring(&mut self) -> Result<String>
Reads a UTF-8 encoded C-style string from the reader until a null terminator (0x00) is encountered.
§Returns
Returns an io::Result<String> containing the read string.
§Errors
This function will return an error if:
- There’s an I/O error while reading from the reader.
- The read bytes are not valid UTF-8.
sourcefn read_fixed_string(&mut self, length: usize) -> Result<String>
fn read_fixed_string(&mut self, length: usize) -> Result<String>
Reads a fixed-length UTF-8 encoded string from the reader.
This function reads exactly length bytes, ignores unknown UTF-8 encodings,
and trims any null bytes found at the end of the string.
§Arguments
length- The number of bytes to read.
§Returns
Returns an io::Result<String> containing the read string.
§Errors
Returns Ok(()) if the read operation is successful, or an Err containing
the I/O error if any reading operation fails.
sourcefn read_enumerable<T: Default + Readable>(
&mut self,
count: usize,
) -> Result<Vec<T>>
fn read_enumerable<T: Default + Readable>( &mut self, count: usize, ) -> Result<Vec<T>>
Reads an enumerable type accumulating the results into a vector of the same type.
This function reads a type containg the trait Readable count times, requiring the
Readable the passed type to implement an iterator.
§Arguments
count- The amount of times to read the specified type.
§Returns
Returns an io::Result<Vec<T>> containing the accumulated results.
§Errors
Returns Ok(Vec<T>) if the read operation is successful, or an Err containing
the I/O error if any reading operation fails.