Skip to main content

ProvenanceTable

Struct ProvenanceTable 

Source
pub struct ProvenanceTable { /* private fields */ }
Expand description

Assigns EntityIds and remembers what each one came from.

One per document. Cloning it clones the whole history, which is what a rebuild-with-rollback needs.

An entry can be forgotten (ProvenanceTable::forget, ProvenanceTable::retain): its id stays issued, so no later entity takes it, and asking for it answers None as for an id from another document.

Implementations§

Source§

impl ProvenanceTable

Source

pub const fn new() -> Self

An empty table.

Source

pub const fn len(&self) -> usize

Number of identities issued, forgotten ones included: the next recorded entity is this plus one.

Source

pub const fn is_empty(&self) -> bool

Whether no identity has been issued.

Source

pub fn record(&mut self, provenance: Provenance) -> EntityId

Record an entity’s provenance and return its identity.

§Panics

If more than u64::MAX - 1 entities are recorded. Not reachable.

Source

pub fn primitive(&mut self, op: OpId, role: Role) -> EntityId

Convenience for Provenance::Primitive.

Source

pub fn derived( &mut self, op: OpId, from: impl IntoIterator<Item = EntityId>, role: Role, ) -> EntityId

Convenience for Provenance::Derived.

Source

pub fn get(&self, id: EntityId) -> Option<&Provenance>

The provenance of id, or None if it belongs to another document or its entry was forgotten.

Source

pub fn forget(&mut self, id: EntityId) -> bool

Drop id’s entry and keep its id issued.

For a document that keeps only what its shapes can still reach: an entity no shape carries and no kept entry derives from answers nothing a reference could ask. Returns whether there was an entry to drop.

Source

pub fn retain(&mut self, keep: impl FnMut(EntityId, &Provenance) -> bool)

Keep the entries keep answers true for and forget the rest, as ProvenanceTable::forget does each one. What is forgotten stops costing memory.

Source

pub fn roots(&self, id: EntityId) -> Vec<EntityId>

Walk id’s derivation back to the entities it ultimately came from.

Returns the roots: entities that are Primitive or Imported. This is how a stale reference is resolved after a rebuild: find what the user originally picked, then find what that became.

Cycles cannot occur, because an entity can only be derived from ids that already existed when it was recorded. The visited set guards against a table assembled by hand or deserialized from a corrupt file.

Source

pub fn iter(&self) -> impl Iterator<Item = (EntityId, &Provenance)>

Every entity with an entry, in the order its identity was issued; forgotten entries are skipped.

For writing a document out: the table is the record of what every entity is, and a file that dropped it would come back as a model whose every reference had to be rebuilt from scratch.

Trait Implementations§

Source§

impl Clone for ProvenanceTable

Source§

fn clone(&self) -> Self

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

impl Debug for ProvenanceTable

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ProvenanceTable

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.