Skip to main content

FileStorage

Struct FileStorage 

Source
pub struct FileStorage { /* private fields */ }
Expand description

A pairing store in one JSON file, behind the storage-file feature.

Creating it creates the file if it is absent and checks one that exists: a file that is not this backend’s format, including one with a version this build does not know, is refused with an error and never rewritten. Every write goes to a temporary file in the same directory and is renamed over the store, so an interrupted write leaves the previous store intact. On Unix the file is created with mode 0600.

The backend holds no records in memory: every call reads the file, and writes hold a lock so two callers in one process cannot lose each other’s record. One process owns the file; a second process writing the same path at the same time is not coordinated, which matches the client’s one-connection design.

Implementations§

Source§

impl FileStorage

Source

pub fn new(path: impl Into<PathBuf>) -> Result<Self>

Opens the store at path, creating it when it does not exist.

The parent directory must exist; this backend creates a file, never a directory. An existing file must be a store of the shape this build writes, or the call returns an error and the file is left untouched.

Source

pub fn path(&self) -> &Path

The file this backend owns.

Trait Implementations§

Source§

impl Debug for FileStorage

Source§

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

Names the file, never its contents.

Source§

impl Storage for FileStorage

Source§

fn pairing_psk(&self) -> Result<Option<[u8; 32]>>

The long-lived pairing PSK the host restored, or None on a device’s first run. Read more
Source§

fn store_pairing_psk(&self, psk: &[u8; 32]) -> Result<()>

Persists the pairing PSK the client drew on this run. Read more
Source§

fn load_pairings(&self) -> Result<Vec<StoredPsk>>

The records of known servers, oldest first. Read more
Source§

fn store_pairing(&self, record: StoredPsk) -> Result<()>

Stores record as the newest record for its server. Read more
Source§

fn remove_pairing(&self, server_id: &str) -> Result<()>

Removes the record for server_id. Read more

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