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§
Sourcefn from_map(map: &HashMap<&str, &str>) -> LoadResult<Self>
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.
Sourcefn keys() -> Vec<&'static str>where
Self: Sized,
fn keys() -> Vec<&'static str>where
Self: Sized,
Get all available persistence keys for this struct
Sourcefn changed_keys(&self) -> &HashSet<&'static str>
fn changed_keys(&self) -> &HashSet<&'static str>
Get all dirty fields (fields that have been modified since last save)
Sourcefn mark_keys_changed(&mut self, keys: &[&'static str])
fn mark_keys_changed(&mut self, keys: &[&'static str])
Mark specific keys as dirty
Sourcefn serialize_changes(&self) -> Result<Vec<(&'static str, String)>, String>
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.
Sourcefn clear_changes(&mut self)
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.