amebazii::types

Trait ToStream

Source
pub trait ToStream {
    // Required method
    fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
       where W: Write + Seek;
}
Expand description

A trait for types that can be serialized to a stream.

This trait defines the write_to method, which allows a type to be serialized (written) to a stream, such as a file or buffer.

§Example

use amebazii::types::{ToStream, Error};
struct MyStruct {
    field1: u32,
    field2: String,
}

impl ToStream for MyStruct {
    fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
    where
        W: std::io::Write + std::io::Seek,
    {
        // Implement the logic to write the struct's fields to the stream
        Ok(())
    }
}

Required Methods§

Source

fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek,

Writes the type’s data to a stream.

This method serializes the implementing type into a provided stream (writer). It is used by the transfer_to and to_bytes functions to write the data to various output formats.

§Parameters
  • writer: A mutable reference to a writer that implements io::Write and io::Seek.
§Returns
  • Ok(()): If the data is successfully written to the stream.
  • Err(Error): If an error occurs while writing to the stream.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§