amebazii::types

Function from_stream

Source
pub fn from_stream<R, T>(reader: &mut R) -> Result<T, Error>
where R: Read + Seek, T: FromStream + Default,
Expand description

Reads a type from a stream.

This function attempts to read a value of type T from a reader that implements both the io::Read and io::Seek traits. The type T must implement the FromStream trait to define how it can be read from the stream, and it must also implement Default to create an instance to populate.

§Parameters

  • reader: A mutable reference to the reader from which data will be read.

§Returns

  • Ok(T): The deserialized value of type T.
  • Err(Error): If an error occurs while reading from the stream.

§Example

use amebazii::types::{from_stream, FromStream, Error};

let mut reader = std::io::Cursor::new(vec![1, 2, 3, 4]);
let my_struct: MyStruct = from_stream(&mut reader).unwrap();