Skip to main content

khive_types/
header.rs

1//! Common header for substrate records.
2
3use crate::{Id128, Namespace, Timestamp};
4
5/// Fields shared by every substrate record (Note, Entity, Event).
6#[derive(Clone, Debug)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Header {
9    pub id: Id128,
10    pub namespace: Namespace,
11    pub created_at: Timestamp,
12    pub updated_at: Timestamp,
13}
14
15impl Header {
16    pub fn new(id: Id128, namespace: Namespace, now: Timestamp) -> Self {
17        Self {
18            id,
19            namespace,
20            created_at: now,
21            updated_at: now,
22        }
23    }
24
25    pub fn touch(&mut self, now: Timestamp) {
26        self.updated_at = now;
27    }
28}