Skip to main content

Store

Struct Store 

Source
pub struct Store<S: Storage> {
    container: Container<S>,
    repo: Repo,
    trail: Trail,
    clock: Clock,
    head: Digest,
    rows: Vec<Row>,
    tags: Tags,
    tail: Tail,
}

Fields§

§container: Container<S>§repo: Repo§trail: Trail

Where this session’s history stands. Beside the repo rather than in it: a step adopts the rev copy this container holds, which is something only the store can read (docs/log-vs-snapshot.md).

§clock: Clock§head: Digest

The digest the next row must name as its parent.

§rows: Vec<Row>

Every row this container’s manifest holds that spends a rev, in rev order: rows()[i] describes rev i + 1. What the history panel, the rev pick and blockworx log all read.

§tags: Tags

What the manifest’s tag rows name its revs. Rebuilt at every open and never handed to the repo.

§tail: Tail

Implementations§

Source§

impl<S: Storage> Store<S>

Source

pub fn create(storage: S, clock: Clock) -> Result<Self, ContainerError>

Lay out a new container and open it at the empty document.

§Errors

As Container::create.

Source

pub async fn creating(storage: S, clock: Clock) -> Result<Self, ContainerError>

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

§Errors

As Self::create.

Source

pub fn seeded( storage: S, clock: Clock, commits: &[Commit], author: &Identity, ) -> Result<Self, SeedFailure>

Lay out a new container and put commits into it, each as one row and one rev of its own.

This is how a scratch session becomes durable: each commit lands as its own rev, so the container’s history is the session’s history. Nothing is trailed — the commits are the new container’s past.

A session that already has a container does not come this way: commits are all this can carry, so the wall times, the authors, the edit/undo/redo kinds and the tags would be flattened into a run of fresh edits by whoever pressed Save-as. That path copies the manifest’s own rows instead (super::prefix::save_through).

§Errors

SeedFailure::Create as Self::create, and SeedFailure::Append naming the commit that did not land — which leaves a container holding the prefix that did.

Source

pub async fn seeding( storage: S, clock: Clock, commits: &[Commit], author: &Identity, ) -> Result<Self, SeedFailure>

Self::seeded for a storage whose futures are not ready when they are made. The commits themselves are folded and written synchronously either way; what a resident container owes its storage afterwards is Self::drain’s.

§Errors

As Self::seeded.

Source

fn seeded_with( self, commits: &[Commit], author: &Identity, ) -> Result<Self, SeedFailure>

Source

pub fn open(storage: S, clock: Clock) -> Result<Self, ContainerError>

Open a container: read the manifest, verify its chain, and read the head rev.

A manifest that does not verify is not a failure to open: the container opens read-only at the last good prefix, with the break as its ReadOnlyReason, because the reader is owed a look at the past that is intact. A manifest with a partial trailing row opens writable, the row dropped and the file cut back to the last whole line.

§Errors

As Container::open — there is no container, or it cannot be read.

Source

pub async fn opening(storage: S, clock: Clock) -> Result<Self, ContainerError>

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

The open is where a resident container is read in — the manifest, every rev and every payload — so everything after it, this function’s own second half included, reads out of memory.

§Errors

As Self::open.

Source

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

Open a container to be read and never written.

The same read as Self::open over a handle that never claimed the lock (Container::reading), so reading someone’s document — or a fixture out of fixtures/ — cannot cost its owner the right to write it. Every write door refuses with Refusal::ReadOnly, which is why this takes no Clock: nothing here mints a row.

§Errors

As Self::open.

Source

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

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

§Errors

As Self::reading.

Source

pub(crate) fn over( container: Container<S>, clock: Clock, ) -> Result<Self, ContainerError>

Read an already-attached container — Self::open’s second half, shared with the prefix Save-as, which lays a container out with a manifest already in it.

§Errors

The manifest that could not be read.

Source

pub fn name(&self) -> Name

What this document is called.

Source

pub fn path(&self) -> Option<&Path>

Where this container sits on a filesystem, for a shell that can name one. None for a container that is not on one.

Source

pub fn rename(&mut self, to: &Name) -> Result<(), Refusal>

Rename this store’s container, keeping the lock and the manifest with it. The document is untouched: only what it is called changes, so nothing is appended and no rev is spent.

§Errors

Refusal::ReadOnly on a container this session may not write — renaming someone else’s open document is not a read — and Refusal::Rename when the container does not move, which leaves the store where it was.

Source

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

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

§Errors

As Self::rename.

Source

pub fn pending(&self) -> usize

How many writes this session has made to its container’s memory and not yet to its storage — what a status line reads “writing…” off. Always zero where the writes are made as they are asked for.

Source

pub async fn drain(&mut self) -> Result<Drained>

Make the writes this session owes its storage, in the order it made them. See Container::drain: a write that does not land costs the container its lock, as a failed append does.

§Errors

The write that did not land.

Source

pub fn repo(&self) -> &Repo

Readable, never writable: Self::submit_edit and its two neighbours are the only way a commit gets into this repo, which is what keeps the repo and the files in step.

Source

pub fn trail(&self) -> &Trail

Where this session’s history stands: what one press would take back, what one would put back, and which rev’s document the head holds.

Source

pub fn document(&self) -> &Document

Source

pub fn access(&self) -> &Access

Source

pub fn read_only_reason(&self) -> Option<&ReadOnlyReason>

Source

pub fn tail(&self) -> Tail

Whether load dropped an unfinished row, and which.

Source

pub fn rows(&self) -> &[Row]

The manifest’s rows, one per rev, in rev order.

Source

pub fn row(&self, at: Rev) -> Option<&Row>

The row rev at was written under, or None for a rev this history does not hold.

Source

pub fn framing(&self, at: Rev) -> Option<&Row>

The row a reader frames rev at from: its own, or — for a step — the row of the act it moves.

A step frames what it moved, so the scope it opens and the view it replays are the ones the act was made in, not where the hand that pressed undo happened to be standing. The row itself still records the undoer’s own circumstances; the derivation happens at read time.

Source

pub fn tags(&self) -> &Tags

What this manifest’s tag rows call its revs.

Source

pub fn document_at(&self, at: Rev) -> Result<Document, Refusal>

The document this container holds at at, payloads and all.

§Errors

Refusal::Unreachable for a rev whose copy the container cannot show.

Source

fn head_hash(&self) -> Digest

What the head row stamps. Read off the row rather than recomputed: the row was written after the bytes landed, and the open checked them against each other.

Source

pub fn submit_edit<'a>( &mut self, commit: Commit, by: impl Into<Attribution<'a>>, ) -> Result<Rev, Refusal>

Fold commit, write its rev, and append its row. See Store’s note on the write path: a write that fails costs the container its lock.

§Errors

Refusal::ReadOnly when this handle may not write, Refusal::Fold when the fold refuses the commit, and Refusal::Append when the row does not reach the file.

Source

pub fn undo<'a>( &mut self, edit: Rev, by: impl Into<Attribution<'a>>, ) -> Result<Rev, Refusal>

Adopt the document the trail’s top entry restores, recorded as an undo of edit.

§Errors

As Self::submit_edit, with Refusal::Step in place of Refusal::Fold when the trail will not take the step, and Refusal::Unreachable for a rev this container cannot read back.

Source

pub fn redo<'a>( &mut self, edit: Rev, by: impl Into<Attribution<'a>>, ) -> Result<Rev, Refusal>

§Errors

As Self::undo.

Source

pub fn tag<'a>( &mut self, at: Rev, name: &str, how: Tagging, by: impl Into<Attribution<'a>>, ) -> Result<(), Refusal>

Put a name on at, or take one off.

One appended row, chained like any other, that no rev is spent on and the trail never hears about: tagging is not an edit, and undo after it still takes back the last one.

§Errors

Refusal::ReadOnly when this handle may not write, Refusal::NoSuchRev for a rev this history does not hold, and Refusal::Append when the row does not reach the file.

Source

fn write(&mut self, step: Step, by: Attribution<'_>) -> Result<Rev, Refusal>

Take the step, write the rev, then append the row. A write that fails leaves this session’s document ahead of the files, so the container gives up its lock rather than carrying on writing into a history with a hole in it.

§Errors

Refusal::ReadOnly when this handle may not write, Refusal::Fold or Refusal::Step when the repo refuses the step, and Refusal::Append when the row does not reach the file.

Source

fn step( &mut self, edit: Rev, direction: Direction, ) -> Result<(Rev, RowKind, String, Vec<EntityRef>), Refusal>

Take one history step, adopting the rev copy this container holds, and carry the stepped row’s own touched names onto the row this step writes — so a step frames what it moved.

Source

fn row_for(&mut self, written: Written<'_>) -> Row

Source

fn parted_from(&mut self, error: Error) -> Refusal

This session’s document is now ahead of the files, so the container gives up its lock rather than carrying on writing into a history with a hole in it.

Auto Trait Implementations§

§

impl<S> !Freeze for Store<S>

§

impl<S> !RefUnwindSafe for Store<S>

§

impl<S> Send for Store<S>
where S: Send,

§

impl<S> !Sync for Store<S>

§

impl<S> Unpin for Store<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Store<S>
where S: UnsafeUnpin,

§

impl<S> !UnwindSafe for Store<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