Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_crypto/src/scheme.rs

1.1 KiB, 9 runs

created by r1870400018:246, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_core::{
2 prelude::*,
3 mem::Extract,
4};
5use oxedyne_fe2o3_data::time::Timestamp;
6use oxedyne_fe2o3_jdat::{
7 prelude::*,
8 try_extract_tup2dat,
9 tup2dat,
10};
11use oxedyne_fe2o3_namex::id::LocalId as SchemeLocalId;
12
13#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
14pub struct SchemeTimestamp {
15 pub t: Timestamp,
16 pub id: SchemeLocalId, // Minimalist mapping to Namex id.
17}
18
19impl ToDat for SchemeTimestamp {
20 fn to_dat(&self) -> Outcome<Dat> {
21 Ok(tup2dat![
22 res!(self.t.to_dat()),
23 res!(self.id.to_dat()),
24 ])
25 }
26}
27
28impl FromDat for SchemeTimestamp {
29 fn from_dat(dat: Dat) -> Outcome<Self> {
30 let mut v = try_extract_tup2dat!(dat);
31 let t = res!(Timestamp::from_dat(v[0].extract()));
32 let id = res!(SchemeLocalId::from_dat(v[1].extract()));
33 Ok(Self {
34 t,
35 id,
36 })
37 }
38}
39
40impl SchemeTimestamp {
41 pub fn now(id: SchemeLocalId) -> Outcome<Self> {
42 Ok(Self {
43 t: res!(Timestamp::now()),
44 id,
45 })
46 }
47}