pub trait PersistentData: DeserializeOwned + Serialize {
// Required method
fn relative_path() -> PathBuf;
// Provided methods
fn path() -> Result<PathBuf, FilesystemError> { ... }
fn load() -> Result<Self, FilesystemError> { ... }
fn load_or_default<T: PersistentData + Default>( ) -> Result<T, FilesystemError> { ... }
fn save(&self) -> Result<(), FilesystemError> { ... }
}Expand description
Defines a serializable struct that should persist on the filesystem inside the Ajour config directory.
Required Methods§
Sourcefn relative_path() -> PathBuf
fn relative_path() -> PathBuf
Only method required to implement PersistentData on an object. Always relative to the config folder for Ajour.
Provided Methods§
Sourcefn path() -> Result<PathBuf, FilesystemError>
fn path() -> Result<PathBuf, FilesystemError>
Returns the full file path. Will create any parent directories that don’t exist.
Sourcefn load() -> Result<Self, FilesystemError>
fn load() -> Result<Self, FilesystemError>
Load from PersistentData::path().
Sourcefn load_or_default<T: PersistentData + Default>() -> Result<T, FilesystemError>
fn load_or_default<T: PersistentData + Default>() -> Result<T, FilesystemError>
Load from PersistentData::path(). If file doesn’t exist, save it to the filesystem as Default
and return that object.
Sourcefn save(&self) -> Result<(), FilesystemError>
fn save(&self) -> Result<(), FilesystemError>
Save to PersistentData::path()
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.