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: StateIdRevision identity — resource, content, parent and sequence.
resource: StringThe resource this is a revision of.
content: StringCanonical JSON representation (representation-sensitive)
content_id: StateIdContent identity — the hash of content alone.
parent_id: Option<StateId>Parent revision id. None only for a resource’s first revision.
sequence: u64Position in this resource’s history. Strictly increasing, never reused.
Authority that produced this revision
timestamp_ms: u64Timestamp when revision was created (informational only, not used for ordering)
metadata: BTreeMap<String, Value>Metadata (preservable with state)
Implementations§
Source§impl StateRevision
impl StateRevision
Sourcepub fn initial(resource: String, content: String, authority: String) -> Self
pub fn initial(resource: String, content: String, authority: String) -> Self
Create a resource’s first revision.
Sourcepub fn child(content: String, parent: &StateRevision, authority: String) -> Self
pub fn child(content: String, parent: &StateRevision, authority: String) -> Self
Create a revision descending from parent, on the parent’s resource.
Sourcepub fn at(
resource: String,
content: String,
parent_id: Option<StateId>,
sequence: u64,
authority: String,
) -> Self
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.
Sourcepub fn verify_integrity(&self) -> bool
pub fn verify_integrity(&self) -> bool
Verify that both identities match what they are computed from.
Sourcepub fn parent(&self) -> Option<&StateId>
pub fn parent(&self) -> Option<&StateId>
Get parent id if this is not a resource’s first revision.
Sourcepub fn equals(&self, other: &StateRevision) -> bool
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.
Sourcepub fn same_content_as(&self, other: &StateRevision) -> bool
pub fn same_content_as(&self, other: &StateRevision) -> bool
Whether two revisions hold the same state, regardless of where in history they occur.