pub trait ReadWrite: Sized {
// Required methods
fn read(reader: impl Read) -> Result<Self>;
fn write(&self, writer: impl Write) -> Result<()>;
// Provided method
fn serialize(&self) -> Vec<u8> ⓘ { ... }
}Expand description
An item which can be read and written.
Required Methods§
Sourcefn read(reader: impl Read) -> Result<Self>
fn read(reader: impl Read) -> Result<Self>
Read an instance of Self.
If the reader yields a reachable serialization of a value, it MUST be readable. In other words, the following round-trip MUST succeed:
let serialization = item.serialize();
let mut serialization = serialization.as_slice();
let item2 = I::read(&mut serialization).unwrap();
// Functional equivalence in all regards, not just `<I as PartialEq>::eq` returning `true`
assert_eq!(item, item2);
assert!(serialization.is_empty());Additionally, the item MUST be self-delimited and MUST NOT read to the end.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".