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
impl DirStore
Sourcepub fn open(dir: impl Into<PathBuf>) -> Result<Self, SessionError>
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 Files for DirStore
impl Files for DirStore
Source§fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>
fn write_file(&self, name: &str, bytes: &[u8]) -> Result<()>
name with bytes, atomically: a reader sees the
old content or the new.Source§fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>
fn append_file(&self, name: &str, bytes: &[u8]) -> Result<()>
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>>
fn read_file(&self, name: &str) -> Result<Vec<u8>>
name; io::ErrorKind::NotFound when there is none.Source§impl Store for DirStore
impl Store for DirStore
Source§fn replace_log(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> Result<(), LogWriteError>
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<()>
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 read_log(&self, name: &str) -> Result<Vec<u8>>
fn read_log(&self, name: &str) -> Result<Vec<u8>>
name; io::ErrorKind::NotFound when there is none.Source§fn append_log(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> Result<(), LogWriteError>
fn append_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>
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§
impl Freeze for DirStore
impl RefUnwindSafe for DirStore
impl Send for DirStore
impl Sync for DirStore
impl Unpin for DirStore
impl UnsafeUnpin for DirStore
impl UnwindSafe for DirStore
Blanket Implementations§
Source§impl<S> AsyncStore for S
impl<S> AsyncStore for S
Source§fn read_log_async(
&self,
name: &str,
) -> impl Future<Output = Result<Vec<u8>, Error>> + WasmCompatSend
fn read_log_async( &self, name: &str, ) -> impl Future<Output = Result<Vec<u8>, Error>> + WasmCompatSend
name.Source§fn append_log_async(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
fn append_log_async( &self, name: &str, len: u64, bytes: &[u8], ) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
Source§fn replace_log_async(
&self,
name: &str,
len: u64,
bytes: &[u8],
) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
fn replace_log_async( &self, name: &str, len: u64, bytes: &[u8], ) -> impl Future<Output = Result<(), LogWriteError>> + WasmCompatSend
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
fn read_file_async( &self, name: &str, ) -> impl Future<Output = Result<Vec<u8>, Error>> + WasmCompatSend
name.Source§fn write_file_async(
&self,
name: &str,
bytes: &[u8],
) -> impl Future<Output = Result<(), Error>> + WasmCompatSend
fn write_file_async( &self, name: &str, bytes: &[u8], ) -> impl Future<Output = Result<(), Error>> + WasmCompatSend
name with bytes, atomically.