aboutsummaryrefslogtreecommitdiff
path: root/server/src/idgen.rs
blob: 0cdc98333e64704a9ec4f17e631d355bbf740485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use tokio::sync::RwLock;

pub struct IdGenerator {
    x: RwLock<u64>,
}

impl Default for IdGenerator {
    fn default() -> Self {
        Self {
            x: Default::default(),
        }
    }
}
impl IdGenerator {
    pub async fn generate(&self) -> u64 {
        // TODO: dummy implementation; ideal would be encrypting the counter
        let mut x = self.x.write().await;
        *x += 1;
        *x
    }
}