pub trait SaveData: Sized {
const SCHEMA: u64;
const VERSION: u32;
const MAX_BYTES: usize = 8_388_608usize;
// Required methods
fn write(&self, document: &mut Document) -> Result<(), SaveError>;
fn read(document: &Document) -> Result<Self, SaveError>;
// Provided methods
fn encode(&self, generation: u64) -> Result<Vec<u8>, SaveError> { ... }
fn decode(data: &[u8]) -> Result<(Self, u64), SaveError> { ... }
}Expand description
Implement explicit older-version migration in read(); reject newer versions. Decode into a temporary value and validate it before returning to the host.
Required Associated Constants§
Provided Associated Constants§
Required Methods§
fn write(&self, document: &mut Document) -> Result<(), SaveError>
fn read(document: &Document) -> Result<Self, SaveError>
Provided Methods§
fn encode(&self, generation: u64) -> Result<Vec<u8>, SaveError>
fn decode(data: &[u8]) -> Result<(Self, u64), SaveError>
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.