pub trait Persist: Sized {
// Required methods
fn load_from<R: Read>(reader: &mut R) -> PersistenceResult<Self>;
fn save_to<W: Write>(&self, writer: &mut W) -> PersistenceResult<()>;
// Provided methods
fn load_from_or_default<R: Read>(reader: &mut R) -> Self
where Self: Default { ... }
fn load_with<R: Read>(reader: R) -> PersistenceResult<Self> { ... }
fn load_with_or_default<R: Read>(reader: R) -> Self
where Self: Default { ... }
fn save_with<W: Write>(&self, writer: W) -> PersistenceResult<()> { ... }
}
Expand description
Trait implemented by types that can be read/written from a Reader/Writer as a simple binary serialisation format.
Required Methods§
sourcefn load_from<R: Read>(reader: &mut R) -> PersistenceResult<Self>
fn load_from<R: Read>(reader: &mut R) -> PersistenceResult<Self>
Load an instance of this type from the given reader.
Provided Methods§
sourcefn load_from_or_default<R: Read>(reader: &mut R) -> Selfwhere
Self: Default,
fn load_from_or_default<R: Read>(reader: &mut R) -> Selfwhere
Self: Default,
Load an instance of this type from the given reader, or return the Default instantiation if it cannot be loaded.
sourcefn load_with<R: Read>(reader: R) -> PersistenceResult<Self>
fn load_with<R: Read>(reader: R) -> PersistenceResult<Self>
Take the given reader and use it to load an instance of this type.
sourcefn load_with_or_default<R: Read>(reader: R) -> Selfwhere
Self: Default,
fn load_with_or_default<R: Read>(reader: R) -> Selfwhere
Self: Default,
Take the given reader and use it to load an instance of this type, or return the Default instantiation if it cannot be loaded.
sourcefn save_with<W: Write>(&self, writer: W) -> PersistenceResult<()>
fn save_with<W: Write>(&self, writer: W) -> PersistenceResult<()>
Take the given writer and use it to save an instance of this type.
Object Safety§
This trait is not object safe.