libmilkyway/
lib.rs

1///
2/// Serialization and deserialization to byte arrays implementation
3/// 
4pub mod serialization;
5
6///
7/// Postquantum PKI implementation
8/// 
9pub mod pki;
10
11///
12/// Standard macros for simplifying writing code
13/// 
14pub mod macros;
15
16///
17/// Common messaging protocol
18/// 
19pub mod message;
20
21///
22/// Communication implementations
23/// 
24pub mod transport;
25
26///
27/// tokio utilities
28/// 
29pub mod tokio;
30
31///
32/// A module for loading dynamic modules
33/// 
34pub mod module;
35
36///
37/// Common protocol for sharing core features with modules
38/// 
39pub mod services;
40
41/// 
42/// CLI utilites
43/// 
44pub mod cli;
45
46
47///
48/// Actor-model architecture utilities
49/// 
50pub mod actor;
51
52use std::time::{SystemTime, UNIX_EPOCH};
53
54///
55/// Get exact timestamp with milliseconds
56/// 
57pub fn get_timestamp_with_milliseconds() -> u128 {
58    let start = SystemTime::now();
59    let since_the_epoch = start.duration_since(UNIX_EPOCH)
60        .expect("Time went backwards");
61    since_the_epoch.as_millis()
62}
63
64/* Library-wide tests begin here */
65#[cfg(test)]
66mod tests {
67    use super::*;
68    use libmilkyway_derive::Serializable;
69    use libmilkyway_derive::Deserializable;
70    use crate::serialization::serializable::Serializable;
71    use crate::serialization::deserializable::Deserializable;
72    use crate::serialization::serializable::Serialized;
73    use serialization::error::SerializationError;
74
75    #[derive(Serializable, Deserializable, Debug, PartialEq)]
76    struct MyStruct {
77        a: u32,
78        b: Vec<u8>,
79    }
80
81    /** Test to check Serializable/Deserializable derive proc macros **/
82    #[test]
83    fn test_serialize_deserialize_my_struct() {
84        let my_struct = MyStruct {
85            a: 42,
86            b: vec![0, 1, 42],
87        };
88
89        let serialized = my_struct.serialize();
90        let (deserialized, _) = MyStruct::from_serialized(&serialized).unwrap();
91
92        assert_eq!(my_struct, deserialized);
93    }
94}
95