pub struct Container<T, Manager> { /* private fields */ }Expand description
A basic owned container allowing managed access to some underlying file.
Implementations§
Source§impl<T, Manager> Container<T, Manager>
impl<T, Manager> Container<T, Manager>
Sourcepub const fn new(value: T, manager: Manager) -> Self
pub const fn new(value: T, manager: Manager) -> Self
Create a new Container from the value and manager directly.
Sourcepub fn into_value(self) -> T
pub fn into_value(self) -> T
Extract the contained state.
Sourcepub fn into_manager(self) -> Manager
pub fn into_manager(self) -> Manager
Extract the container manager.
Sourcepub const fn manager(&self) -> &Manager
pub const fn manager(&self) -> &Manager
Gets a reference to the contained file manager.
It is inadvisable to manipulate the manager manually.
Source§impl<T, Format, Lock, Mode> Container<T, FileManager<Format, Lock, Mode>>
impl<T, Format, Lock, Mode> Container<T, FileManager<Format, Lock, Mode>>
Sourcepub fn open<P: AsRef<Path>>(
path: P,
format: Format,
) -> Result<Self, Error<Format::FormatError>>where
Mode: Reading,
pub fn open<P: AsRef<Path>>(
path: P,
format: Format,
) -> Result<Self, Error<Format::FormatError>>where
Mode: Reading,
Opens a new Container, returning an error if the file at the given path does not exist.
Sourcepub fn create_overwrite<P: AsRef<Path>>(
path: P,
format: Format,
value: T,
) -> Result<Self, Error<Format::FormatError>>
pub fn create_overwrite<P: AsRef<Path>>( path: P, format: Format, value: T, ) -> Result<Self, Error<Format::FormatError>>
Opens a new Container, creating a file at the given path if it does not exist, and overwriting its contents if it does.
Sourcepub fn create_or<P: AsRef<Path>>(
path: P,
format: Format,
value: T,
) -> Result<Self, Error<Format::FormatError>>
pub fn create_or<P: AsRef<Path>>( path: P, format: Format, value: T, ) -> Result<Self, Error<Format::FormatError>>
Opens a new Container, writing the given value to the file if it does not exist.
Sourcepub fn create_or_else<P: AsRef<Path>, C>(
path: P,
format: Format,
closure: C,
) -> Result<Self, Error<Format::FormatError>>where
C: FnOnce() -> T,
pub fn create_or_else<P: AsRef<Path>, C>(
path: P,
format: Format,
closure: C,
) -> Result<Self, Error<Format::FormatError>>where
C: FnOnce() -> T,
Opens a new Container, writing the result of the given closure to the file if it does not exist.
Sourcepub fn create_or_default<P: AsRef<Path>>(
path: P,
format: Format,
) -> Result<Self, Error<Format::FormatError>>where
T: Default,
pub fn create_or_default<P: AsRef<Path>>(
path: P,
format: Format,
) -> Result<Self, Error<Format::FormatError>>where
T: Default,
Opens a new Container, writing the default value of T to the file if it does not exist.
Source§impl<T, Format, Lock, Mode> Container<T, FileManager<Format, Lock, Mode>>where
Format: FileFormat<T>,
impl<T, Format, Lock, Mode> Container<T, FileManager<Format, Lock, Mode>>where
Format: FileFormat<T>,
Sourcepub fn refresh(&mut self) -> Result<T, Error<Format::FormatError>>where
Mode: Reading,
pub fn refresh(&mut self) -> Result<T, Error<Format::FormatError>>where
Mode: Reading,
Reads a value from the managed file, replacing the current state in memory.