amebazii::types

Function transfer_to

Source
pub fn transfer_to<W, T>(obj: &T, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, T: ToStream,
Expand description

Transfers a type’s data to a stream.

This function serializes the data of the given object (obj) and writes it to the provided writer. The object must implement the ToStream trait, which specifies how to serialize the data to the stream.

§Parameters

  • obj: A reference to the object that will be written to the stream.
  • writer: A mutable reference to the writer that will receive the serialized data.

§Returns

  • Ok(()): If the object was successfully written to the stream.
  • Err(Error): If an error occurred while writing the object to the stream.

§Example

use amebazii::types::{transfer_to, ToStream};

let my_struct = MyStruct { field1: 42, field2: String::from("Hello") };
let mut buf = Vec::new();
transfer_to(&my_struct, &mut buf).unwrap();