pub struct Container<S: Storage> {
storage: S,
access: Access,
kept: Kept,
}Fields§
§storage: S§access: Access§kept: KeptImplementations§
Source§impl<S: Storage> Container<S>
impl<S: Storage> Container<S>
Sourcepub fn create(storage: S, now: WallTime) -> Result<Self, ContainerError>
pub fn create(storage: S, now: WallTime) -> Result<Self, ContainerError>
Lay out a new container and take its lock.
§Errors
ContainerError::Exists if the storage already holds a manifest,
or the underlying I/O failure.
Sourcepub async fn creating(storage: S, now: WallTime) -> Result<Self, ContainerError>
pub async fn creating(storage: S, now: WallTime) -> Result<Self, ContainerError>
Self::create for a storage whose futures are not ready when they
are made.
The layout goes down through the storage itself rather than through the journal: there is no container to owe a write to until this returns.
§Errors
As Self::create.
Sourcepub fn create_holding(
storage: S,
now: WallTime,
rows: &[u8],
) -> Result<Self, ContainerError>
pub fn create_holding( storage: S, now: WallTime, rows: &[u8], ) -> Result<Self, ContainerError>
The same, with rows already in it — the prefix Save-as, which
copies an existing manifest’s lines rather than re-writing them.
The bytes go down before the lock is taken, so nothing can append
into the middle of them.
§Errors
As Self::create.
Sourcepub async fn creating_holding(
storage: S,
now: WallTime,
rows: &[u8],
) -> Result<Self, ContainerError>
pub async fn creating_holding( storage: S, now: WallTime, rows: &[u8], ) -> Result<Self, ContainerError>
§Errors
Sourcepub fn open(storage: S, now: WallTime) -> Result<Self, ContainerError>
pub fn open(storage: S, now: WallTime) -> Result<Self, ContainerError>
Open an existing container, taking its lock if nobody holds it.
§Errors
ContainerError::NotAContainer when there is no manifest to open, or
the underlying I/O failure.
Sourcepub async fn opening(storage: S, now: WallTime) -> Result<Self, ContainerError>
pub async fn opening(storage: S, now: WallTime) -> Result<Self, ContainerError>
Self::open for a storage whose futures are not ready when they
are made — which, being a resident one, is where the container is
read into memory.
§Errors
As Self::open.
Sourcepub fn reading(storage: S) -> Result<Self, ContainerError>
pub fn reading(storage: S) -> Result<Self, ContainerError>
Open an existing container to be read and never written, leaving the lock untouched.
The honest mode for a reader: claiming the lock merely to look would either demote the session editing that container or hold a lock against one nobody is writing, and a handle that will refuse every write anyway has no business taking either.
§Errors
As Self::open.
Sourcepub async fn opening_to_read(storage: S) -> Result<Self, ContainerError>
pub async fn opening_to_read(storage: S) -> Result<Self, ContainerError>
§Errors
As Self::reading.
async fn require_manifest(storage: &S) -> Result<(), ContainerError>
async fn attach(storage: S, now: WallTime) -> Result<Self, ContainerError>
Sourceasync fn kept(storage: &S) -> Result<Kept, ContainerError>
async fn kept(storage: &S) -> Result<Kept, ContainerError>
Read the container in, for a storage that says its reads are not ready when they are made: the manifest, then every rev and every payload.
pub fn storage(&self) -> &S
pub fn access(&self) -> &Access
Sourcepub fn read(&self, at: &Entry) -> Result<Option<Vec<u8>>>
pub fn read(&self, at: &Entry) -> Result<Option<Vec<u8>>>
The bytes at at, off the shelf when the container is held in
memory and out of the storage when it is not.
§Errors
The read that did not work — which is not the same as nothing being there.
Sourcepub fn write(&self, at: &Entry, bytes: &[u8]) -> Result<()>
pub fn write(&self, at: &Entry, bytes: &[u8]) -> Result<()>
§Errors
The write that did not land — which a held container’s cannot, since it has only reached memory when this returns.
fn append(&self, at: &Entry, bytes: &[u8]) -> Result<()>
fn truncate(&self, at: &Entry, len: u64) -> Result<()>
Sourcepub fn pending(&self) -> usize
pub fn pending(&self) -> usize
How many writes this container has made to its memory and not yet to its storage. Zero for a container that writes as it goes.
Sourcepub async fn drain(&mut self) -> Result<Drained>
pub async fn drain(&mut self) -> Result<Drained>
Make the writes this container owes, one at a time, in the order it made them — the payload before the rev, the rev before the row that names it, as a container that writes as it goes makes them.
A write that does not land leaves this session’s document ahead of the files, so the container gives up its lock, as a failed append does where there is no journal. What it had not yet written goes with the lock: nothing more is written to a container this session has parted from.
§Errors
The write that did not land.
fn next_owed(&self) -> Option<(Entry, Op)>
fn forget_what_is_owed(&self)
Sourcepub fn rename(&mut self, to: &Name) -> Result<()>
pub fn rename(&mut self, to: &Name) -> Result<()>
Rename this container — which renames the document, since the container’s name is what the document is called.
The session carries on through it: every entry is named relative to the container, so an edit made after the rename lands in the same manifest the edits before it did, and the lock moves with what it locks.
§Errors
std::io::ErrorKind::AlreadyExists when something already stands
under that name, or the rename’s own failure.
Sourcepub async fn renaming_to(&mut self, to: &Name) -> Result<()>
pub async fn renaming_to(&mut self, to: &Name) -> Result<()>
Sourcepub fn demote(&mut self, reason: ReadOnlyReason)
pub fn demote(&mut self, reason: ReadOnlyReason)
Give up the right to write, releasing the lock with it. Called when the manifest turns out not to verify, and when an append fails.
Sourcepub fn read_manifest(&self) -> Result<String>
pub fn read_manifest(&self) -> Result<String>
§Errors
The underlying read failure.
Sourcepub fn write_rev(
&self,
rev: Rev,
document: &Document,
) -> Result<Digest, WriteRefusal>
pub fn write_rev( &self, rev: Rev, document: &Document, ) -> Result<Digest, WriteRefusal>
Write the document as it stands at rev into revs/, its payloads
into assets/, and hand back the digest of the rev’s bytes.
Called before the row that names the rev is appended, so the manifest never names bytes a crash could still take away — and the payloads land before the rev that references them, for the same reason one level down.
§Errors
WriteRefusal::ReadOnly if this handle does not hold the lock,
or the write that did not land.
Sourcepub fn read_rev(&self, rev: Rev) -> Result<Document, RevFault>
pub fn read_rev(&self, rev: Rev) -> Result<Document, RevFault>
The document this container holds at rev, payloads and all.
§Errors
revs::RevFault: no file, one that is not a document this build
reads, or artwork the container cannot hand back.
Sourcepub fn append_row(&self, row: &Row) -> Result<(), WriteRefusal>
pub fn append_row(&self, row: &Row) -> Result<(), WriteRefusal>
Append one row and make it durable before returning: the line and its newline in one write, then an fsync. A crash anywhere in here loses at most this row, and loses it visibly — the manifest then ends without a newline, which is how load knows to drop it.
§Errors
WriteRefusal::ReadOnly if this handle does not hold the lock,
or the underlying write failure.
Sourcepub fn truncate_manifest(&self, bytes: u64) -> Result<(), WriteRefusal>
pub fn truncate_manifest(&self, bytes: u64) -> Result<(), WriteRefusal>
Cut a partial trailing row off, so the next append does not splice itself onto half a line.
§Errors
As Self::append_row.
Trait Implementations§
Auto Trait Implementations§
impl<S> !Freeze for Container<S>
impl<S> !RefUnwindSafe for Container<S>
impl<S> Send for Container<S>where
S: Send,
impl<S> !Sync for Container<S>
impl<S> Unpin for Container<S>where
S: Unpin,
impl<S> UnsafeUnpin for Container<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for Container<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more