pub trait Persistable: Sized {
type Snapshot: Serialize + DeserializeOwned;
// Required methods
fn to_snapshot(&self) -> Self::Snapshot;
fn from_snapshot(snapshot: Self::Snapshot) -> Result<Self, String>;
// Provided methods
fn to_bytes(&self) -> Result<Vec<u8>, String> { ... }
fn from_bytes(data: &[u8]) -> Result<Self, String> { ... }
}Expand description
Trait for indexes that can be persisted
Required Associated Types§
Sourcetype Snapshot: Serialize + DeserializeOwned
type Snapshot: Serialize + DeserializeOwned
The snapshot type for this index
Required Methods§
Sourcefn to_snapshot(&self) -> Self::Snapshot
fn to_snapshot(&self) -> Self::Snapshot
Create a snapshot of the current state
Sourcefn from_snapshot(snapshot: Self::Snapshot) -> Result<Self, String>
fn from_snapshot(snapshot: Self::Snapshot) -> Result<Self, String>
Restore from a snapshot
Provided Methods§
Sourcefn from_bytes(data: &[u8]) -> Result<Self, String>
fn from_bytes(data: &[u8]) -> Result<Self, String>
Deserialize from bytes (JSON format)
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.