pub struct Operation {
pub kind: OperationKind,
pub parents: Vec<OpId>,
pub intent_id: Option<IntentId>,
}Expand description
The operation as a whole — its kind and the causal predecessors
it assumes. The OpId is computed from this plus a sorted view
of parents.
Operations without parents are valid and represent “applies to
the empty repository” or “applies to the synthetic genesis
state.” lex store migrate v1→v2 will produce parentless ops
for stages it can’t trace back to a clear predecessor.
Fields§
§kind: OperationKind§parents: Vec<OpId>Operations whose produces this op assumes. Sorted before
hashing for canonical form. Empty for ops against the empty
repo.
intent_id: Option<IntentId>The intent that caused this op, if known. Optional because
operations produced outside an agent harness (e.g. a human
running lex publish directly) don’t have one.
Including the intent in the canonical hash means the same
logical change made under different intents produces
different OpIds — causally distinct events should hash
distinctly. Ops with intent_id: None keep their existing
hashes (the field is omitted from the canonical JSON via
skip_serializing_if), so this is backwards-compatible
for stores written before #131.
Implementations§
Source§impl Operation
impl Operation
Sourcepub fn new(kind: OperationKind, parents: impl IntoIterator<Item = OpId>) -> Self
pub fn new(kind: OperationKind, parents: impl IntoIterator<Item = OpId>) -> Self
Construct an operation against zero or more parents. Caller supplies parents in any order; canonicalization sorts them before hashing.
Sourcepub fn with_intent(self, intent_id: impl Into<IntentId>) -> Self
pub fn with_intent(self, intent_id: impl Into<IntentId>) -> Self
Tag this operation with the intent that produced it. The builder shape keeps existing call sites untouched; agent harnesses that record intent call this once before applying the op.
Sourcepub fn op_id(&self) -> OpId
pub fn op_id(&self) -> OpId
Compute this operation’s content-addressed identity under the
current production canonical form (OperationFormat::CURRENT).
Stable across runs and machines: same (kind, payload, sorted parents, intent_id) produces the same OpId. The
invariant #129’s automatic-dedup behavior relies on.
Sourcepub fn op_id_in(&self, format: OperationFormat) -> OpId
pub fn op_id_in(&self, format: OperationFormat) -> OpId
Compute the OpId under a specific canonical-form version.
Used by crate::migrate to derive new OpIds when porting
a store across format versions. Production code should call
Self::op_id.
Sourcepub fn canonical_bytes(&self) -> Vec<u8> ⓘ
pub fn canonical_bytes(&self) -> Vec<u8> ⓘ
The byte sequence that gets hashed to produce Self::op_id
under the current canonical form. Equivalent to
self.canonical_bytes_in(OperationFormat::CURRENT).
Exposed (not just consumed by op_id) so golden tests can pin
the exact pre-image. Not equal to serde_json::to_vec(&op)
in general — the on-disk JSON skips empty parents and
None intent_id, while the canonical form always emits a
(sorted, deduped) parents array. See canonical.rs for the
full V1 canonical-form spec.
Sourcepub fn canonical_bytes_in(&self, format: OperationFormat) -> Vec<u8> ⓘ
pub fn canonical_bytes_in(&self, format: OperationFormat) -> Vec<u8> ⓘ
The pre-image hashed under a specific canonical-form version.
Today every OperationFormat variant routes to V1’s encoder
(only V1 exists in production). When V2 lands, this match
gains an arm and the migration tool’s encoder closure routes
here.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Operation
impl<'de> Deserialize<'de> for Operation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Operation
impl StructuralPartialEq for Operation
Auto Trait Implementations§
impl Freeze for Operation
impl RefUnwindSafe for Operation
impl Send for Operation
impl Sync for Operation
impl Unpin for Operation
impl UnsafeUnpin for Operation
impl UnwindSafe for Operation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.