amebazii::types

Function to_bytes

Source
pub fn to_bytes<T>(obj: &T) -> Result<Vec<u8>, Error>
where T: ToStream,
Expand description

Serializes an object into a vector of bytes.

This function serializes the object (obj) into a Vec<u8>.

§Parameters

  • obj: A reference to the object to be serialized.

§Returns

  • Ok(Vec<u8>): A vector of bytes representing the serialized object.
  • Err(Error): If an error occurs while writing the object to the byte vector.

§Example

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

let my_struct = MyStruct { field1: 42, field2: String::from("Hello") };
let bytes = to_bytes(&my_struct).unwrap();