crdt_sample/
nodeId.rs

1use std::{fmt::{Display, Debug}, mem::size_of};
2
3#[derive(PartialEq, Eq, Hash, Clone)]
4pub struct NodeId {
5    port: i64,
6    addr: String,
7}
8
9impl NodeId {
10    pub fn new(port: i64, addr: String) -> Self {
11        Self { port, addr }
12    }
13
14    pub fn get_bytes_size(&self) -> usize {
15        return size_of::<i64>() + self.addr.len();
16    }
17}
18
19impl Display for NodeId {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        write!(f, "{}{}", self.addr, self.port)
22    }
23}
24
25impl Debug for NodeId{
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(f, "{}", self)
28    }
29}