pub trait Encode {
// Required method
fn encode(&self, writer: &mut Writer);
}Expand description
A type that can be written as Cyclone bytes.
The implementation is the schema: it decides which fields are written, in which order, and with which Cyclone type. Nothing here inspects the Rust type to work that out.
use cyclone_runtime::{Encode, Writer};
struct Item { id: u32, name: String }
impl Encode for Item {
fn encode(&self, writer: &mut Writer) {
writer.write_u32(self.id);
writer.write_string(&self.name);
}
}
let mut writer = Writer::new();
Item { id: 42, name: "Sword".to_owned() }.encode(&mut writer);
assert_eq!(writer.len(), 13);Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".