pathfinding/id/
instance_id.rs1use crate::id::id_generator::MAX_VALUE_U64;
2
3pub type InstanceIdType = u128;
4
5pub struct InstanceIdStruct {
6 time: i64,
7 value: u64,
8}
9
10impl From<InstanceIdStruct> for InstanceIdType {
12 fn from(value: InstanceIdStruct) -> Self {
13 let time = (value.time as InstanceIdType) << 64;
14 let value = value.value as InstanceIdType;
15 time + value
16 }
17}
18
19impl From<InstanceIdType> for InstanceIdStruct {
21 fn from(id: InstanceIdType) -> Self {
22 let mut result = id;
23 let value = (result & (MAX_VALUE_U64 as u128)) as u64;
24 result >>= 64;
25 let time = result as i64;
26 InstanceIdStruct{time, value }
27 }
28}
29
30impl InstanceIdStruct {
31
32 #[allow(dead_code)]
33 fn new_from_id(id: InstanceIdType) -> Self {
34 id.into()
35 }
36
37 pub(crate) fn new_from_more(time: i64, value: u64) -> Self {
38 InstanceIdStruct{time, value}
39 }
40}