pub struct IdempotencyKey(pub String);Expand description
Stable idempotency key of a command (I14).
Tuple Fields§
§0: StringImplementations§
Source§impl IdempotencyKey
impl IdempotencyKey
Sourcepub fn derive(
account: &AccountId,
turn_id: &TurnId,
case_ref: &CaseRef,
origin: &CommandOrigin,
command: &Value,
) -> Result<Self, HashError>
pub fn derive( account: &AccountId, turn_id: &TurnId, case_ref: &CaseRef, origin: &CommandOrigin, command: &Value, ) -> Result<Self, HashError>
Derives the key as blake3(canonical_json({domain, account, turn_id, case_ref, origin, command})).
The key is stable for the same inputs across processes and library
versions that share the domain prefix. It changes when any input changes,
including the expected revision inside case_ref: a command re-planned
against a newer revision is a new command, while a crash-recovery replay
of the same turn reproduces the same key.
§Examples
use turnframe_core::prelude::*;
use serde_json::json;
let account = AccountId::from("acct");
let turn = TurnId::nil();
let case_ref = CaseRef::new("trip", "i1", CaseRevision(3));
let origin = CommandOrigin::DirectSafeUserAct {
evidence_digest: Digest::of_bytes(b"evidence"),
};
let command = json!({ "set_name": { "value": "Lisbon" } });
let key = IdempotencyKey::derive(&account, &turn, &case_ref, &origin, &command)?;
// The same turn replayed after a crash derives the same key ...
assert_eq!(
key,
IdempotencyKey::derive(&account, &turn, &case_ref, &origin, &command)?
);
// ... but a command planned against a newer revision is a new command.
let newer = case_ref.with_revision(CaseRevision(4));
assert_ne!(
key,
IdempotencyKey::derive(&account, &turn, &newer, &origin, &command)?
);Trait Implementations§
Source§impl Clone for IdempotencyKey
impl Clone for IdempotencyKey
Source§impl Debug for IdempotencyKey
impl Debug for IdempotencyKey
Source§impl<'de> Deserialize<'de> for IdempotencyKey
impl<'de> Deserialize<'de> for IdempotencyKey
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for IdempotencyKey
impl Display for IdempotencyKey
impl Eq for IdempotencyKey
Source§impl Hash for IdempotencyKey
impl Hash for IdempotencyKey
Source§impl JsonSchema for IdempotencyKey
impl JsonSchema for IdempotencyKey
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl Ord for IdempotencyKey
impl Ord for IdempotencyKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for IdempotencyKey
impl PartialEq for IdempotencyKey
Source§impl PartialOrd for IdempotencyKey
impl PartialOrd for IdempotencyKey
Source§impl Serialize for IdempotencyKey
impl Serialize for IdempotencyKey
impl StructuralPartialEq for IdempotencyKey
Auto Trait Implementations§
impl Freeze for IdempotencyKey
impl RefUnwindSafe for IdempotencyKey
impl Send for IdempotencyKey
impl Sync for IdempotencyKey
impl Unpin for IdempotencyKey
impl UnsafeUnpin for IdempotencyKey
impl UnwindSafe for IdempotencyKey
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
Compare self to
key and return true if they are equal.