Skip to main content

StateRevision

Struct StateRevision 

Source
pub struct StateRevision {
    pub id: StateId,
    pub resource: String,
    pub content: String,
    pub content_id: StateId,
    pub parent_id: Option<StateId>,
    pub sequence: u64,
    pub authority: String,
    pub timestamp_ms: u64,
    pub metadata: BTreeMap<String, Value>,
}
Expand description

An immutable, resource-scoped historical state.

A revision is a revision of a resource. Two resources holding identical content are distinct revisions, and a resource that returns to a value it previously held records a new revision rather than resurrecting the old one.

§Two identities, deliberately

id is the revision identity: what distinguishes one historical occurrence from another. It is computed over the resource, the content, the parent and a per-resource sequence, so content equality is not identity.

content_id is the content identity, the hash of the canonical content alone. It is what makes a revision verifiable against its own bytes, and it is what deduplicates content comparisons — two revisions of the same state share a content_id and differ in id.

Conflating these two was the defect the identity contract found: a revert produced a revision whose identity already existed, so committing it overwrote the earlier one and closed a cycle in the parent chain.

Fields§

§id: StateId

Revision identity — resource, content, parent and sequence.

§resource: String

The resource this is a revision of.

§content: String

Canonical JSON representation (representation-sensitive)

§content_id: StateId

Content identity — the hash of content alone.

§parent_id: Option<StateId>

Parent revision id. None only for a resource’s first revision.

§sequence: u64

Position in this resource’s history. Strictly increasing, never reused.

§authority: String

Authority that produced this revision

§timestamp_ms: u64

Timestamp when revision was created (informational only, not used for ordering)

§metadata: BTreeMap<String, Value>

Metadata (preservable with state)

Implementations§

Source§

impl StateRevision

Source

pub fn initial(resource: String, content: String, authority: String) -> Self

Create a resource’s first revision.

Source

pub fn child(content: String, parent: &StateRevision, authority: String) -> Self

Create a revision descending from parent, on the parent’s resource.

Source

pub fn at( resource: String, content: String, parent_id: Option<StateId>, sequence: u64, authority: String, ) -> Self

Create a revision at an explicit position in a resource’s history.

Source

pub fn verify_integrity(&self) -> bool

Verify that both identities match what they are computed from.

Source

pub fn parent(&self) -> Option<&StateId>

Get parent id if this is not a resource’s first revision.

Source

pub fn equals(&self, other: &StateRevision) -> bool

Whether two revisions are the same revision.

Revision identity, not content equality: two revisions of the same state on the same resource are not equal.

Source

pub fn same_content_as(&self, other: &StateRevision) -> bool

Whether two revisions hold the same state, regardless of where in history they occur.

Trait Implementations§

Source§

impl Clone for StateRevision

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 StateRevision

Source§

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

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

impl<'de> Deserialize<'de> for StateRevision

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for StateRevision

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V