pub trait JuteSerializable: Sized {
// Required methods
fn serialize<W: Write>(&self, out: &mut W) -> Result<(), JuteError>;
fn deserialize<R: Read>(bytes: &mut R) -> Result<Self, JuteError>;
}Expand description
Trait for types that can be serialized to and deserialized from the Jute binary encoding format.
JuteSerializable is implemented by all structs generated from
Jute schema files. It provides low-level, streaming-based
serialization and deserialization APIs that follow the
Apache Jute wire format.
§Design
- Serialization writes data sequentially to any
Writeimplementation (for exampleVec<u8>,File, orTcpStream). - Deserialization reads data sequentially from any
Readimplementation. - No buffering is performed internally; callers may wrap streams in buffered readers or writers if needed.
This design allows Jute-generated types to be used efficiently in both file-based and network-based protocols.
§Example
use std::io::Cursor;
use jute::JuteSerializable;
// x can be of any type that implement JuteSerializable
let x = "test".to_string();
// Serialize into a byte buffer
let mut buffer = Vec::new();
x.serialize(&mut buffer).unwrap();
// Deserialize from the buffer
let mut cursor = Cursor::new(buffer);
let x = String::deserialize(&mut cursor).unwrap();§Errors
Both serialization and deserialization return JuteError if:
- An I/O error occurs while reading or writing
- The input stream is malformed or truncated
- The encoded data violates the Jute type rules
§Notes
- Implementations must read and write fields in the exact order defined in the Jute schema.
- The
deserializemethod assumes the input stream is positioned at the start of a valid Jute-encoded value.
Required Methods§
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.