Skip to main content

Container

Struct Container 

Source
pub struct Container<S: Storage> {
    storage: S,
    access: Access,
    kept: Kept,
}

Fields§

§storage: S§access: Access§kept: Kept

Implementations§

Source§

impl<S: Storage> Container<S>

Source

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.

Source

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.

Source

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.

Source

pub async fn creating_holding( storage: S, now: WallTime, rows: &[u8], ) -> Result<Self, ContainerError>

Source

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.

Source

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.

Source

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.

Source

pub async fn opening_to_read(storage: S) -> Result<Self, ContainerError>

§Errors

As Self::reading.

Source

async fn require_manifest(storage: &S) -> Result<(), ContainerError>

Source

async fn attach(storage: S, now: WallTime) -> Result<Self, ContainerError>

Source

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.

Source

pub fn storage(&self) -> &S

Source

pub fn name(&self) -> Name

What this container is called — the document’s own name.

Source

pub fn access(&self) -> &Access

Source

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.

Source

pub fn exists(&self, at: &Entry) -> Result<bool>

§Errors

The read that did not work.

Source

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.

Source

fn append(&self, at: &Entry, bytes: &[u8]) -> Result<()>

Source

fn truncate(&self, at: &Entry, len: u64) -> Result<()>

Source

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.

Source

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.

Source

fn next_owed(&self) -> Option<(Entry, Op)>

Source

fn forget_what_is_owed(&self)

Source

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.

Source

pub async fn renaming_to(&mut self, to: &Name) -> Result<()>

Self::rename for a storage whose futures are not ready when they are made.

§Errors

As Self::rename.

Source

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.

Source

fn release(&mut self)

Let go of the lock, if this handle was holding it.

Source

pub fn read_manifest(&self) -> Result<String>

§Errors

The underlying read failure.

Source

pub fn assets(&self) -> Artwork<'_, S>

Where this container’s artwork is read and written.

Source

pub fn revs(&self) -> Revs<'_, S>

Where this container keeps the document at every rev.

Source

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.

Source

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.

Source

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.

Source

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.

Source§

impl<S: Storage> Container<S>

Source

pub async fn glance(storage: S) -> Result<Option<Glance>, ContainerError>

A glance at the container in storage, read without touching its lock. None for one no rev has been written into yet.

§Errors

As Self::reading, or the manifest that could not be read.

Trait Implementations§

Source§

impl<S: Storage> Drop for Container<S>

Source§

fn drop(&mut self)

The lock’s lifetime is the writable handle’s lifetime, rather than something a caller has to remember.

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

§

impl<T> Instrument for T

§

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

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

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.

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either [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,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either [OwoColorize::bg] or a color-specific method, such as [OwoColorize::on_yellow], Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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