Skip to main content

RecordStore

Struct RecordStore 

pub struct RecordStore(/* private fields */);
Expand description

A RecordSet several widgets share via a handle, so two tabs on the same file stay one document; single-threaded on purpose, since a Mutex here would guard against nothing.

Implementations§

§

impl RecordStore

pub fn with_history_or_why<R>( &self, id: &RecordId, f: impl FnOnce(&mut AutoCommit, &mut UndoLog) -> R, ) -> Result<R, HistoryUnavailable>

Self::with_history, saying why the record could not be changed now: the store is in use, the record is lent to a frame or still being created, or it is not open here.

§Errors

Why f did not run.

§

impl RecordStore

pub fn route( &self, checkout: &RecordCheckout, ) -> Result<RouteSpec, RecordOpenError>

Checked custody-to-wire mapping. Primary stays record=None on every host.

pub fn schedule_committed_history(&self, id: &RecordId) -> Result<(), String>

Schedule this already committed History result through its existing writer, without sweeping or closing other owners’ unfinished edits. # Errors The cache could not take the document, or the store is busy and took nothing.

pub fn content_revision(&self) -> String

Cheap content witness for retained projections over open records: base heads cover committed changes, pending_ops the live typing transaction, and the record identity makes opening or closing a document invalidate a snapshot.

pub fn package_and_home(&self) -> (String, String)

pub fn held_parts(&self, base: &RecordId) -> Vec<u64>

The numbers of the parts of the chain base this store holds, in order: those open here, and those kept on this device unopened. Listing reads the store’s index, so a frame loop asks on Self::kept_revision instead of every frame.

pub fn note_kept(&self)

Tell the store that a record it does not have open was kept in its backend by someone else (a workspace’s replication, delivering a part another device started), so what follows the records it keeps looks again. Callable while a frame reads the store.

pub fn announce(&self, records: impl IntoIterator<Item = RecordId>)

Peers wrote records of this store’s trees, which it does not hold: whatever follows those trees takes them up at once, as after Self::note_kept. Callable while a frame reads the store.

pub fn announced_parts(&self, base: &RecordId) -> Vec<u64>

The numbers of the parts of the chain base peers wrote (Self::announce), in order.

pub fn kept_revision(&self) -> u64

Moves whenever the store is told something arrived for what follows it: Self::note_kept, Self::announce, Self::note_workspace_answered.

pub fn open_parts(&self, base: &RecordId) -> Vec<u64>

The numbers of the parts of the chain base open here and ready to read, in order. Reads no index, so it is cheap enough for every frame.

pub fn window_records(&self, kind: &RecordKind) -> Vec<(RecordId, AutoCommit)>

Every window default record of kind this package keeps in this workspace, sorted by id, as last made durable: what an app’s windows started, so a closed window’s document is reached again. Read without taking a writer; a record that cannot be read, is retired or is not of kind here is left out and logged.

pub fn try_open_record( &self, want: &RecordCheckout, ) -> Result<RecordOpenOutcome, RecordOpenError>

Open Existing only; a missing document is never implicitly initialized. # Errors Reports ownership contention, absence, identity or schema refusal and storage failures.

pub fn reserve_record( &self, want: &RecordCheckout, ) -> Result<RecordReservation, RecordOpenError>

Reserve a New identity with its gate and no document/history/writer yet: the workspace’s own records are reserved as shared writers, any other as its only writer.

§Errors

Refuses collisions, malformed existing data and unavailable storage.

pub fn is_ready(&self, id: &RecordId) -> bool

pub fn save_status( &self, id: &RecordId, ) -> Result<RecordSaveStatus, RecordOpenError>

Inspect durability without closing a typing transaction or scheduling work.

§Errors

Reports missing/reserved records.

pub fn wake_on_save_progress( &self, id: &RecordId, wake: Arc<dyn Fn() + Send + Sync>, )

Have wake called whenever Self::save_status of id may change without input: its store resolving its writer’s writes, or a host acknowledging a portable cache. A memory-only record never changes. Sample again once armed: a write that landed before is not heard of.

pub fn await_submitted(&self, id: &RecordId) -> Result<(), String>

Block until the store has committed or refused every write id’s writer already submitted, without submitting its pending edits: the acknowledgement Self::save_status reports, awaited instead of polled.

§Errors

Reports missing/busy records, an unpersisted record, and the writer’s outstanding failure.

pub fn durability_error(&self, id: &RecordId) -> Option<String>

pub fn try_flush(&self) -> Result<(), String>

Request current changes once and await actual acknowledgements for every record.

§Errors

Returns record-specific storage failures; a subsequent explicit retry sends a full checkpoint.

pub fn try_flush_written(&self) -> Result<(), String>

Write out what is not stored yet, and report only what failed: the records are the store’s from then on, and the store’s own thread commits them (RecordSet::try_flush_written).

pub fn new(set: RecordSet) -> RecordStore

Share an existing set.

pub fn open(manifest_id: impl Into<String>) -> RecordStore

The production store: see RecordSet::open.

pub fn in_memory() -> RecordStore

A store that never touches disk: see RecordSet::in_memory.

pub fn open_record(&self, want: &RecordCheckout) -> bool

Open want if it is not open already. Returns whether this opened it.

pub fn create_record( &self, want: &RecordCheckout, ) -> Result<(), RecordOpenError>

Create exactly the new resource named by its owning action. Reopening existing tabs must use existing-only admission instead.

§Errors

Refuses existing identities, unavailable persistence, and invalid scope.

pub fn action_generation( &self, id: &RecordId, ) -> Result<Option<u64>, RecordOpenError>

Generation of the record-owned action frame, for retained callers that need to invalidate a previously resolved operation.

§Errors

Returns Busy if the record set is borrowed, or MissingRecord if the record is not open.

pub fn merge_peer_document( &self, checkout: &RecordCheckout, document: Vec<u8>, ) -> Result<bool, String>

Merge a peer’s full document into an open record, exactly as a collaborator’s state arriving over sync is merged: validated first, and without moving the local author’s undo history onto the peer’s edits. Returns whether anything changed.

§Errors

Returns why the peer’s document was refused; the record is unchanged.

pub fn merge_peer_changes( &self, checkout: &RecordCheckout, changes: Vec<u8>, ) -> Result<bool, String>

Merge another replica’s incremental changes (what Self::replication_delta answers there) into the open record, as the workspace’s broker delivers one window’s changes to the others on the record. Whether anything changed.

§Errors

The record is not open here or the changes do not merge.

pub fn withdraw_refused( &self, id: &RecordId, refused: &[ChangeHash], reason: &str, ) -> Result<Option<Vec<ChangeHash>>, String>

Withdraw from the open record id the changes refused names, which the workspace refused, with every local change made on top of them, and note one RecordRefusal per action they carried, saying reason (for a person), for the app to take (Self::take_refusals).

A refused change is shared state nowhere but here, and a peer holds back every change that depends on one it never receives: kept, it would show as sent forever and silence everything written after it. The document becomes what it was without them, saved whole; local undo starts over, since its steps may name withdrawn changes. A replication frontier past them must be rebased onto the heads this returns. Returns None when nothing was withdrawn: the record holds none of them, or they are its creation (still noted).

§Errors

The record is not open here or its owner is busy, or the document does not rebuild.

pub fn hold_notice( &self, id: &RecordId, text: String, ) -> Result<(), RecordOpenError>

Say text of what was just done to the open record id once the workspace it is shared in keeps it (WorkspaceNotices): at once when no host replicates it, never when the workspace refuses it. The pending action is committed first, so the change it names is among the heads held.

§Errors

The record is not open here or its owner is busy.

pub fn workspace_settled(&self, id: &RecordId)

The workspace’s host answered every commit of record id it published: what was held for them is said (Self::take_said).

pub fn take_said(&self, id: &RecordId) -> Vec<String>

What to say now of record id (Self::hold_notice), each once.

pub fn take_refusals(&self, id: &RecordId) -> Vec<RecordRefusal>

The refusals of record id noted since the last call (Self::withdraw_refused).

pub fn replication_delta( &self, id: &RecordId, frontier: &mut DocumentFrontier, ) -> Result<(Vec<u8>, Vec<ChangeHash>), RecordOpenError>

Changes to the open record id that frontier has not covered, for a host replicating open records itself (a browser page over the relay). The record goes whole, another replica’s changes included; a route publishes its own alone (Self::own_delta). The pending action is committed first, as for a save. Advance the frontier with the returned heads only once the delta was accepted.

§Errors

The record is not open here or its owner is busy.

pub fn own_delta( &self, id: &RecordId, frontier: &mut DocumentFrontier, ) -> Result<(Vec<u8>, Vec<ChangeHash>), RecordOpenError>

The changes to the open record id this replica made and frontier has not published yet, for a route, which publishes its own device’s changes and never another replica’s (crate::state::DocumentFrontier::pending_delta). The pending action is committed first, as for a save. Advance the frontier with the returned heads only once the delta was accepted.

§Errors

The record is not open here or its owner is busy.

pub fn migrate<T>( &self, id: &RecordId, migrate: impl FnOnce(&mut AutoCommit) -> Result<T, String>, ) -> Result<T, String>

Bring the open record id up with migrate, and note the actors it wrote as among this replica’s own: a migration is one housekeeping change whose actor is derived from the document rather than being this device’s, so a route publishing this replica’s own changes (crate::state::DocumentFrontier::pending_delta) sends it too.

§Errors

The record is not open here, its owner is busy, or migrate refused.

pub fn replication_snapshot( &self, id: &RecordId, ) -> Result<(Vec<u8>, Vec<ChangeHash>), RecordOpenError>

The open record id as a whole-document snapshot with its heads, for a replica’s first publication.

§Errors

The record is not open here or its owner is busy.

pub fn merge_replica( &self, checkout: &RecordCheckout, mutation: DocumentMutation, ) -> Result<(bool, Vec<ChangeHash>), String>

Merge a replica’s mutation into the open record, validating the record’s identity on a private copy first; local undo stays local. Returns whether the document changed and the change hashes the mutation carried, for the replicating frontier’s observe.

§Errors

The bytes are not a valid mutation of this record, or it is not open.

pub fn with<R>( &self, id: &RecordId, f: impl FnOnce(&mut AutoCommit) -> R, ) -> Option<R>

Do something with a record’s document. None if the record is not open here.

pub fn takes_writes(&self) -> bool

Whether the store takes a write now: not while something reads or changes it (a frame’s read of a record holds it).

pub fn read<R>( &self, id: &RecordId, f: impl FnOnce(&AutoCommit) -> R, ) -> Option<R>

pub fn with_history<R>( &self, id: &RecordId, f: impl FnOnce(&mut AutoCommit, &mut UndoLog) -> R, ) -> Option<R>

Do something with a record’s document and its history — commit an action, undo one.

pub fn read_history<R>( &self, id: &RecordId, read: impl FnOnce(&AutoCommit, &UndoLog) -> R, ) -> Option<R>

Inspect committed history without turning a pending burst into a boundary.

pub fn open_records(&self) -> Vec<RecordCheckout>

Every record this store holds.

pub fn open_tree_records(&self) -> Vec<RecordCheckout>

The open records that belong to another’s tree (RecordId::tree), ready to read; none while a frame holds the store.

pub fn tick(&self) -> Result<(), String>

Offer every open record to its writer. Once per idle tick.

§Errors

A record’s cache reports that it could not take the document.

pub fn flush(&self) -> Result<(), String>

Write out every open record and wait for it to land.

§Errors

Each record’s writer that reports a storage failure, by record.

§

impl RecordStore

pub fn wake_on_arrival(&self, reader: WakeHandle)

Wake the window reader belongs to whenever another replica’s change arrives in this store: merged into an open record (Self::merge_replica), or kept for a record it follows (Self::note_kept, Self::announce). Nothing else tells a window that its records moved, so without it what arrived waits for the window’s next input or timer. A closed window’s handle is dropped.

pub fn note_workspace_answered(&self, id: RecordId)

The workspace’s hosts sent everything they hold of id, a record this store asked them for (RecordId::arrives_on_demand), or no host is connected to ask: what of it is here is all there is for now. What reads it and still lacks it (a part held from its genesis that nothing arrived in) shows it unavailable rather than loading, until something of it arrives, which clears this. Wakes the store’s readers. Callable while a frame reads the store.

pub fn workspace_answered(&self, id: &RecordId) -> bool

Whether the workspace’s hosts sent everything they hold of id (Self::note_workspace_answered) and nothing of it arrived since.

§

impl RecordStore

pub fn begin_opening( &self, want: &RecordCheckout, ) -> Result<bool, RecordOpenError>

Begin opening the record want off the frame, when it is the workspace’s own document and this device holds it: its bytes are read now and decoded on a thread of their own. Until it is taken in it is not open, and the window that opened it shows what it can without it. Whether it began; a record that is not here, or is opened another way, opens as before.

§Errors

The record’s owner or bytes cannot be had.

pub fn home(&self) -> String

The workspace these records are kept in: what a window keys what it keeps on this device by the workspace, before any record of it is read.

pub fn is_opening(&self, id: &RecordId) -> bool

Whether the record id is being opened off the frame and is not taken in yet.

pub fn opening(&self, want: &RecordCheckout) -> RecordOpening

The record want as it opens off the frame.

Trait Implementations§

§

impl Clone for RecordStore

§

fn clone(&self) -> RecordStore

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
§

impl Debug for RecordStore

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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
§

impl<T> AsAny for T
where T: 'static,

§

fn as_any(&self) -> &(dyn Any + 'static)

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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 = 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> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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
§

impl<T> ErasedDestructor for T
where T: 'static,