Trait Perstruct

Source
pub trait Perstruct: Sized {
    // Required methods
    fn from_map(map: &HashMap<&str, &str>) -> LoadResult<Self>;
    fn keys() -> Vec<&'static str>
       where Self: Sized;
    fn changed_keys(&self) -> &HashSet<&'static str>;
    fn mark_keys_changed(&mut self, keys: &[&'static str]);
    fn serialize_changes(&self) -> Result<Vec<(&'static str, String)>, String>;
    fn clear_changes(&mut self);
}
Expand description

Trait defining persistence behavior for structs. This trait is automatically implemented by the perstruct macro.

Required Methods§

Source

fn from_map(map: &HashMap<&str, &str>) -> LoadResult<Self>

Load an instance from a key-value map. The map should contain serialized field values as strings, keyed by field names or custom keys.

Source

fn keys() -> Vec<&'static str>
where Self: Sized,

Get all available persistence keys for this struct

Source

fn changed_keys(&self) -> &HashSet<&'static str>

Get all dirty fields (fields that have been modified since last save)

Source

fn mark_keys_changed(&mut self, keys: &[&'static str])

Mark specific keys as dirty

Source

fn serialize_changes(&self) -> Result<Vec<(&'static str, String)>, String>

Get all changes made to the struct since last save. Returns a vector of (key, serialized_value) pairs for modified fields.

Source

fn clear_changes(&mut self)

Mark all current changes as saved. This resets the change tracking state.

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§