Skip to main content

Record

Struct Record 

Source
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>

Source

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.

Source

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.

Source

pub const fn id(&self) -> RecordId

Record identifier.

Source

pub const fn timestamp(&self) -> Timestamp

Record timestamp.

Source

pub const fn actor(&self) -> Actor<'a>

The actor (who).

Source

pub const fn action(&self) -> Action<'a>

The action (what).

Source

pub const fn target(&self) -> Target<'a>

The target (where).

Source

pub const fn outcome(&self) -> Outcome

The outcome (result).

Source

pub const fn prev_hash(&self) -> Digest

Hash of the immediately preceding record in the chain.

For the genesis record this is Digest::ZERO.

Source

pub const fn hash(&self) -> Digest

Hash of this record, computed over all other fields.

Trait Implementations§

Source§

impl<'a> Clone for Record<'a>

Source§

fn clone(&self) -> Record<'a>

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<'a> Debug for Record<'a>

Source§

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

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

impl From<&Record<'_>> for OwnedRecord

Available on crate feature alloc only.
Source§

fn from(record: &Record<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for Record<'a>

Source§

fn eq(&self, other: &Record<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for Record<'a>

Source§

impl<'a> Eq for Record<'a>

Source§

impl<'a> StructuralPartialEq for Record<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Record<'a>

§

impl<'a> RefUnwindSafe for Record<'a>

§

impl<'a> Send for Record<'a>

§

impl<'a> Sync for Record<'a>

§

impl<'a> Unpin for Record<'a>

§

impl<'a> UnsafeUnpin for Record<'a>

§

impl<'a> UnwindSafe for Record<'a>

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<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> 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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.