use alloc::string::String;
use crate::clock::Timestamp;
use crate::hash::Digest;
use crate::record::{Action, Actor, Outcome, Record, RecordId, Target};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct OwnedRecord {
pub id: RecordId,
pub timestamp: Timestamp,
pub actor: String,
pub action: String,
pub target: String,
pub outcome: Outcome,
pub prev_hash: Digest,
pub hash: Digest,
}
impl OwnedRecord {
#[inline]
pub fn from_record(record: &Record<'_>) -> Self {
Self {
id: record.id(),
timestamp: record.timestamp(),
actor: String::from(record.actor().as_str()),
action: String::from(record.action().as_str()),
target: String::from(record.target().as_str()),
outcome: record.outcome(),
prev_hash: record.prev_hash(),
hash: record.hash(),
}
}
#[inline]
pub fn as_record(&self) -> Record<'_> {
Record::new(
self.id,
self.timestamp,
Actor::new(&self.actor),
Action::new(&self.action),
Target::new(&self.target),
self.outcome,
self.prev_hash,
self.hash,
)
}
}
impl From<&Record<'_>> for OwnedRecord {
#[inline]
fn from(record: &Record<'_>) -> Self {
Self::from_record(record)
}
}