soil_client/utils/
id_sequence.rs1#[derive(Debug, Default)]
11pub struct IDSequence {
13 next_id: u64,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
21pub struct SeqID(u64);
22
23impl std::fmt::Display for SeqID {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 write!(f, "{}", self.0)
26 }
27}
28
29impl IDSequence {
30 pub fn new() -> Self {
32 Default::default()
33 }
34
35 pub fn next_id(&mut self) -> SeqID {
37 let id = SeqID(self.next_id);
38 self.next_id += 1;
39
40 id
41 }
42}
43
44impl Into<u64> for SeqID {
45 fn into(self) -> u64 {
46 self.0
47 }
48}
49
50impl From<u64> for SeqID {
51 fn from(value: u64) -> Self {
52 SeqID(value)
53 }
54}