FileDatabase

Type Alias FileDatabase 

Source
pub type FileDatabase<D, F> = Database<D, File, F>;
Available on crate feature file-backend only.
Expand description

A file-backed database.

Note: this requires its futures to be executed on the Tokio 0.3 runtime.

Aliased Type§

pub struct FileDatabase<D, F> { /* private fields */ }

Implementations§

Source§

impl<D, F> FileDatabase<D, F>
where F: Format<D>,

Source

pub async fn load_from_path<P>(path: P) -> Result<Self, KoitError>
where P: AsRef<Path>,

Construct the file-backed database from the given path. This attempts to load data from the given file.

§Errors

If the file cannot be read, or the formatter cannot decode the data, an error variant will be returned.

Source

pub async fn load_from_path_or_else<P, T>( path: P, factory: T, ) -> Result<Self, KoitError>
where P: AsRef<Path>, T: FnOnce() -> D,

Construct the file-backed database from the given path. If the file does not exist, the file is created. Then factory is called and its return value is used as the initial value. This data is immediately and saved to file.

Source

pub async fn load_from_path_or_default<P>(path: P) -> Result<Self, KoitError>
where P: AsRef<Path>, D: Default,

Same as load_from_path_or_else, except it uses Default instead of a factory.