PersistentData

Trait PersistentData 

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

Source

fn relative_path() -> PathBuf

Only method required to implement PersistentData on an object. Always relative to the config folder for Ajour.

Provided Methods§

Source

fn path() -> Result<PathBuf, FilesystemError>

Returns the full file path. Will create any parent directories that don’t exist.

Source

fn load() -> Result<Self, FilesystemError>

Load from PersistentData::path().

Source

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.

Source

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.

Implementors§