pub struct Record<'a> { /* private fields */ }Expand description
A single audited event in the chain.
A record is intentionally borrowed: its string fields point at caller memory. This keeps the append hot path allocation-free. Sinks that need to persist a record across the lifetime of the borrow must encode it before returning.
§Example
use audit_trail::{Action, Actor, Digest, Outcome, Record, RecordId, Target, Timestamp};
let record = Record::new(
RecordId::GENESIS,
Timestamp::from_nanos(0),
Actor::new("system"),
Action::new("chain.init"),
Target::new("chain:0"),
Outcome::Success,
Digest::ZERO,
Digest::ZERO,
);
assert_eq!(record.actor().as_str(), "system");Implementations§
Source§impl<'a> Record<'a>
impl<'a> Record<'a>
Sourcepub const fn new(
id: RecordId,
timestamp: Timestamp,
actor: Actor<'a>,
action: Action<'a>,
target: Target<'a>,
outcome: Outcome,
prev_hash: Digest,
hash: Digest,
) -> Self
pub const fn new( id: RecordId, timestamp: Timestamp, actor: Actor<'a>, action: Action<'a>, target: Target<'a>, outcome: Outcome, prev_hash: Digest, hash: Digest, ) -> Self
Construct a record from its constituent parts.
The crate’s crate::Chain is normally responsible for producing
records. This constructor is exposed so that custom storage layers
and verifiers can reconstruct records when reading them back.
Sourcepub const fn with_hash(self, hash: Digest) -> Self
pub const fn with_hash(self, hash: Digest) -> Self
Return a copy of this record with hash replaced.
Useful when constructing a record in two steps: build a draft with a
placeholder hash (typically Digest::ZERO), feed it through a
hasher to derive its real digest, then swap the hash in.
Sourcepub const fn prev_hash(&self) -> Digest
pub const fn prev_hash(&self) -> Digest
Hash of the immediately preceding record in the chain.
For the genesis record this is Digest::ZERO.
Trait Implementations§
Source§impl From<&Record<'_>> for OwnedRecord
Available on crate feature alloc only.
impl From<&Record<'_>> for OwnedRecord
alloc only.