Skip to main content

DirStore

Struct DirStore 

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

A Store in the directory it was opened on, whose folders are made as files are written. Each change locks the directory’s lock file, so stores open on one directory, in this process or another, take turns; reads take no lock. Cloning opens the same directory.

Implementations§

Source§

impl DirStore

Source

pub fn open(dir: impl Into<PathBuf>) -> Result<Self, SessionError>

The session in dir, which need not exist yet. Nothing is written.

§Errors

SessionError::OldLayout when dir holds a top-level *.jsonl file, as a session saved by an older rig does; it is left as it is. SessionError::Io when dir cannot be listed.

Trait Implementations§

Source§

impl Clone for DirStore

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 Files for DirStore

Source§

fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Replaces the file name with bytes, atomically: a reader sees the old content or the new.
Source§

fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>

Adds bytes at the end of the file name, which it creates when there is none.
Source§

fn read_file(&self, name: &str) -> Result<Vec<u8>>

The file name; io::ErrorKind::NotFound when there is none.
Source§

fn remove_file(&self, name: &str) -> Result<()>

Removes the file name; removing one that is not there succeeds.
Source§

fn files(&self) -> Result<Vec<String>>

The names of the files, in no particular order.
Source§

impl Store for DirStore

Source§

fn replace_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

The new log is written beside, synced and renamed over the old one: the one synced write, as it is rare and replaces history.

Source§

fn destroy(&self) -> Result<()>

Each folder is renamed to a trash name inside the directory, so it is gone at once, then removed; a second call removes what a crash left of the first. The lock file stays.

Source§

fn logs(&self) -> Result<Vec<String>>

The names of the logs, in no particular order.
Source§

fn read_log(&self, name: &str) -> Result<Vec<u8>>

The whole log name; io::ErrorKind::NotFound when there is none.
Source§

fn append_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Appends bytes to the log name if it is len bytes long now (0 when there is none, which it then starts); else LogWriteError::Changed, writing nothing. The check and the append are one step for every writer of the store, other processes included, so of two writers that read the log at the same length one appends and the other is refused. A log that shrank and grew back to exactly len bytes since it was read is not told apart; rig shrinks a log only by setting a torn last line aside, or by rewrite and Self::destroy, which are for a stopped session.

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<S> AsyncStore for S
where S: Store + ?Sized,

Source§

fn read_log_async( &self, name: &str, ) -> impl Future<Output = Result<Vec<u8>, Error>> + WasmCompatSend

The whole log name.
Source§

fn append_log_async( &self, name: &str, len: u64, bytes: &[u8], ) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend

Appends bytes to the log name if it is len bytes long now (Store::append_log).
Source§

fn replace_log_async( &self, name: &str, len: u64, bytes: &[u8], ) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend

Replaces the log name with bytes if it is len bytes long now, atomically and durably (Store::replace_log).
Source§

fn read_file_async( &self, name: &str, ) -> impl Future<Output = Result<Vec<u8>, Error>> + WasmCompatSend

The file name.
Source§

fn write_file_async( &self, name: &str, bytes: &[u8], ) -> impl Future<Output = Result<(), Error>> + WasmCompatSend

Replaces the file name with bytes, atomically.
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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