Skip to main content

State

Struct State 

Source
pub struct State { /* private fields */ }

Implementations§

Source§

impl State

Source

pub fn load(file: &Path) -> Self

Reads the state file. A missing or unreadable file gives the defaults. An entry whose value is not a string is kept apart (see State::has_invalid_value) and does not affect the other entries. A file that cannot be used gives the defaults: a read error other than “not found”, or content that is not a JSON object. A missing or blank file is a normal first run. After an unusable file, the next State::save first copies whatever file it finds, unless it already holds exactly the document to save, to <name>.invalid-<unix seconds>-<n>. That covers a file that was malformed, and one that was only unreadable or half-written at load time and is valid by the time of the save. State::save fails, without replacing the file, if it cannot read the file or write the copy. Only space, tab, carriage return and line feed count as blank. A non-string value keeps its exact JSON text, such as a number with more digits than u64 or f64 hold. Keys and values saved under a Space’s former id are read as the Space’s own (see crate::former_ids); the file is not changed.

Source

pub fn get(&self, key: &str) -> Option<&str>

The string value of key. None for a missing key and for a key whose stored value is not a string: use State::has_invalid_value to tell them apart before calling State::set.

Source

pub fn has_invalid_value(&self, key: &str) -> bool

True when the file holds a non-string value for key that has not been replaced or removed. A caller that must not overwrite unreadable data skips State::set while this is true; calling State::set or State::remove is the explicit reset.

Source

pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>)

Stores value, replacing any value, including an invalid one.

Source

pub fn remove(&mut self, key: &str)

Deletes key, including an invalid value.

Source

pub fn save(&self, file: &Path) -> Result<()>

Writes the file atomically: a temporary file in the same directory, then a rename over the old file. Invalid entries read by State::load are written back with their exact JSON text. A current file that is not a JSON object, or that differs from this state after a failed load, is copied aside first (see State::load). The first successful save after a failed load ends the check, so later saves make no more copies.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

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

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

impl Default for State

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for State

Source§

impl PartialEq for State

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for State

Auto Trait Implementations§

§

impl !Freeze for State

§

impl Forget for State

§

impl Move for State

§

impl RefUnwindSafe for State

§

impl Send for State
where NodeRef<Owned, String, String, LeafOrInternal>: Send, BoxRaw<(String, String)>: Send, NodeRef<Owned, String, RawJson, LeafOrInternal>: Send, BoxRaw<(String, RawJson)>: Send, Atomic<bool>: Send,

§

impl Sync for State
where NodeRef<Owned, String, String, LeafOrInternal>: Sync, BoxRaw<(String, String)>: Sync, NodeRef<Owned, String, RawJson, LeafOrInternal>: Sync, BoxRaw<(String, RawJson)>: Sync, Atomic<bool>: Sync,

§

impl Unpin for State
where *const LeafNode<String, String> is !null: Unpin, Box<(String, String)>: Unpin, *const LeafNode<String, RawJson> is !null: Unpin, Box<(String, RawJson)>: Unpin, Align1<u8>: Unpin,

§

impl UnsafeUnpin for State
where *const LeafNode<String, String> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, String)>>: UnsafeUnpin, *const LeafNode<String, RawJson> is !null: UnsafeUnpin, PhantomData<Box<(String, RawJson)>>: UnsafeUnpin, Align1<u8>: UnsafeUnpin,

§

impl UnwindSafe for State

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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

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

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