Container

Struct Container 

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

Source

pub const fn new(value: T, manager: Manager) -> Self

Create a new Container from the value and manager directly.

Source

pub fn into_value(self) -> T

Extract the contained state.

Source

pub fn into_manager(self) -> Manager

Extract the container manager.

Source

pub const fn manager(&self) -> &Manager

Gets a reference to the contained file manager.

It is inadvisable to manipulate the manager manually.

Source

pub const fn get(&self) -> &T

Gets a reference to the contained value.

You may also operate on the container directly with Deref instead.

Source

pub fn get_mut(&mut self) -> &mut T

Gets a mutable reference to the contained value.

You may also operate on the container directly with DerefMut instead.

Source§

impl<T, Format, Lock, Mode> Container<T, FileManager<Format, Lock, Mode>>
where Format: FileFormat<T>, Lock: FileLock, Mode: FileMode,

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>,

Source

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.

Source

pub fn commit(&self) -> Result<(), Error<Format::FormatError>>
where Mode: Writing,

Writes the current in-memory state to the managed file.

Source

pub fn overwrite(&mut self, value: T) -> Result<(), Error<Format::FormatError>>
where Mode: Writing,

Writes the given state to the managed file, replacing the in-memory state.

Source§

impl<T, Format, Lock, Mode> Container<T, FileManager<Format, Lock, Mode>>
where Lock: FileLock,

Source

pub fn close(self) -> Result<T>

Unlocks and closes this Container, returning the contained state.

Trait Implementations§

Source§

impl<T: Debug, Manager: Debug> Debug for Container<T, Manager>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, Manager> Deref for Container<T, Manager>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T, Manager> DerefMut for Container<T, Manager>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T, Manager> From<Container<T, Manager>> for ContainerShared<T, Manager>

Available on crate feature shared only.
Source§

fn from(container: Container<T, Manager>) -> Self

Converts to this type from the input type.
Source§

impl<T, Manager> From<Container<T, Manager>> for ContainerSharedAsync<T, Manager>

Available on crate feature shared-async only.
Source§

fn from(container: Container<T, Manager>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T, Manager> Freeze for Container<T, Manager>
where T: Freeze, Manager: Freeze,

§

impl<T, Manager> RefUnwindSafe for Container<T, Manager>
where T: RefUnwindSafe, Manager: RefUnwindSafe,

§

impl<T, Manager> Send for Container<T, Manager>
where T: Send, Manager: Send,

§

impl<T, Manager> Sync for Container<T, Manager>
where T: Sync, Manager: Sync,

§

impl<T, Manager> Unpin for Container<T, Manager>
where T: Unpin, Manager: Unpin,

§

impl<T, Manager> UnwindSafe for Container<T, Manager>
where T: UnwindSafe, Manager: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.