Skip to main content

Storage

Struct Storage 

Source
pub struct Storage {
    root: PathBuf,
    gate: Mutex<()>,
}
Expand description

Reads and writes settings.json, accounts.json, and theme.css in the data folder.

One lock serializes every read and write, so read-modify-write updates can’t lose changes.

Fields§

§root: PathBuf§gate: Mutex<()>

Implementations§

Source§

impl Storage

Source

pub fn new(root: PathBuf) -> Self

Creates storage rooted at root. Files are created on first write.

Source

pub fn root(&self) -> &Path

Returns the data folder.

Source

pub fn load_settings(&self) -> Result<Settings, StorageError>

Loads settings, or the defaults when none are saved.

Source

pub fn save_settings(&self, settings: &Settings) -> Result<(), StorageError>

Validates and atomically replaces the saved settings.

Source

pub fn update_settings<T>( &self, update: impl FnOnce(&mut Settings) -> Result<T, StorageError>, ) -> Result<T, StorageError>

Loads, changes, validates, and saves settings under one lock. Nothing is written when update fails.

Source

pub fn record_version(&self, current: &Version) -> Result<bool, StorageError>

Saves current as the last version that opened and returns whether it’s newer than the version that opened before. The first run on this device isn’t an update. Data saved before 0.4.8 has no version, so it counts as an update.

Source

pub fn load_accounts(&self) -> Result<Vec<StoredAccount>, StorageError>

Loads the saved accounts, or none when the file doesn’t exist.

Source

pub fn update_accounts<T>( &self, update: impl FnOnce(&mut Vec<StoredAccount>) -> Result<T, StorageError>, ) -> Result<T, StorageError>

Loads, changes, validates, and saves accounts under one lock. Nothing is written when update fails.

Source

pub fn load_theme(&self) -> Result<String, StorageError>

Loads the custom theme CSS, or none when it isn’t saved.

Source

pub fn save_theme(&self, css: &str) -> Result<(), StorageError>

Validates and atomically replaces the custom theme CSS.

Source

fn load_settings_unlocked(&self) -> Result<Settings, StorageError>

Loads settings without taking the lock. Callers must hold it.

Source

fn load_accounts_unlocked(&self) -> Result<Vec<StoredAccount>, StorageError>

Loads accounts without taking the lock. Callers must hold it. Secret-like fields saved by older versions are removed and the file is rewritten without them.

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more