pub struct MessageId { /* private fields */ }
Implementations§
Source§impl MessageId
impl MessageId
Sourcepub fn new() -> MessageId
pub fn new() -> MessageId
Generate a new MessageId
§Examples
use nson::message_id::MessageId;
let id = MessageId::new();
println!("{:?}", id);
Examples found in repository?
examples/main.rs (line 6)
5fn main() {
6 let id = MessageId::new();
7
8 println!("{:?}", id);
9 println!("{:?}", id.timestamp());
10 println!("{:?}", id.bytes());
11
12 let a = A { b: B(123) };
13
14 let ret = encode::to_nson(&a);
15 println!("{:?}", ret);
16
17 let ret = decode::from_nson::<A>(ret.unwrap());
18 println!("{:?}", ret);
19
20 let m = nson::msg! {"a": [123i32, 456f32], "b": "hello"};
21 println!("{:?}", m);
22 println!("{}", m);
23}
Sourcepub fn with_bytes(bytes: [u8; 12]) -> Self
pub fn with_bytes(bytes: [u8; 12]) -> Self
Generate an MessageId with bytes
§Examples
use nson::message_id::MessageId;
let id = MessageId::with_bytes([1, 111, 157, 189, 157, 247, 247, 220, 156, 134, 213, 115]);
assert_eq!(format!("{}", id), "016f9dbd9df7f7dc9c86d573")
Sourcepub fn with_string(str: &str) -> Result<MessageId>
pub fn with_string(str: &str) -> Result<MessageId>
Generate an MessageId with string. Provided string must be a 12-byte hexadecimal string
§Examples
use nson::message_id::MessageId;
let id = MessageId::with_string("016f9dbd9df7f7dc9c86d573").unwrap();
assert_eq!(format!("{}", id), "016f9dbd9df7f7dc9c86d573")
Sourcepub fn bytes(&self) -> [u8; 12]
pub fn bytes(&self) -> [u8; 12]
12-byte binary representation of this MessageId.
Examples found in repository?
examples/main.rs (line 10)
5fn main() {
6 let id = MessageId::new();
7
8 println!("{:?}", id);
9 println!("{:?}", id.timestamp());
10 println!("{:?}", id.bytes());
11
12 let a = A { b: B(123) };
13
14 let ret = encode::to_nson(&a);
15 println!("{:?}", ret);
16
17 let ret = decode::from_nson::<A>(ret.unwrap());
18 println!("{:?}", ret);
19
20 let m = nson::msg! {"a": [123i32, 456f32], "b": "hello"};
21 println!("{:?}", m);
22 println!("{}", m);
23}
Sourcepub fn timestamp(&self) -> u64
pub fn timestamp(&self) -> u64
Timstamp of this MessageId
Examples found in repository?
examples/main.rs (line 9)
5fn main() {
6 let id = MessageId::new();
7
8 println!("{:?}", id);
9 println!("{:?}", id.timestamp());
10 println!("{:?}", id.bytes());
11
12 let a = A { b: B(123) };
13
14 let ret = encode::to_nson(&a);
15 println!("{:?}", ret);
16
17 let ret = decode::from_nson::<A>(ret.unwrap());
18 println!("{:?}", ret);
19
20 let m = nson::msg! {"a": [123i32, 456f32], "b": "hello"};
21 println!("{:?}", m);
22 println!("{}", m);
23}
pub fn zero() -> MessageId
pub fn is_zero(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MessageId
impl<'de> Deserialize<'de> for MessageId
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for MessageId
impl Ord for MessageId
Source§impl PartialOrd for MessageId
impl PartialOrd for MessageId
impl Copy for MessageId
impl Eq for MessageId
impl StructuralPartialEq for MessageId
Auto Trait Implementations§
impl Freeze for MessageId
impl RefUnwindSafe for MessageId
impl Send for MessageId
impl Sync for MessageId
impl Unpin for MessageId
impl UnwindSafe for MessageId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.