pub trait Savable<A, F>{
    // Required methods
    fn filename(&self) -> String;
    fn create(&self) -> A;

    // Provided methods
    fn file_path(&self) -> PathBuf { ... }
    fn create_and_save(&self, path: &Path) -> A { ... }
    fn load(&self, path: &Path) -> Result<A, Box<dyn Error>> { ... }
    fn get(&self) -> A { ... }
}
Expand description

A trait for flag operators that can be saved in a file once computed for the first time.

A is the type of the stored object. The operator operate on flags of type F.

Required Methods§

source

fn filename(&self) -> String

Name of the file where the operator can be saved.

source

fn create(&self) -> A

Compute the object.

Provided Methods§

source

fn file_path(&self) -> PathBuf

Path to the corresponding file.

source

fn create_and_save(&self, path: &Path) -> A

(Re)create the object, save it in the corresponding file and return it.

source

fn load(&self, path: &Path) -> Result<A, Box<dyn Error>>

Load the object if the file exists and is valid.

source

fn get(&self) -> A

Function to automatically load the object if the file exists and is valid, or create and save it otherwise.

Implementors§