Skip to main content

Persistable

Trait Persistable 

Source
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§

Source

type Snapshot: Serialize + DeserializeOwned

The snapshot type for this index

Required Methods§

Source

fn to_snapshot(&self) -> Self::Snapshot

Create a snapshot of the current state

Source

fn from_snapshot(snapshot: Self::Snapshot) -> Result<Self, String>

Restore from a snapshot

Provided Methods§

Source

fn to_bytes(&self) -> Result<Vec<u8>, String>

Serialize to bytes (JSON format)

Source

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.

Implementors§