Skip to content

Commit

Permalink
Amend team id to incrementing i64; not random
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeleke committed Dec 18, 2024
1 parent 9aa2b12 commit abf3a6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ dioxus-logger = "0.6.0"
dioxus-web = "0.6.0"
getrandom = { version = "0.2.15", features = ["js"] }
gloo-storage = "0.3.0"
rand = "0.8.5"
lazy_static = "1.5.0"
# rand = "0.8.5"
serde = { version = "1.0.215", features = ["derive"] }
thiserror = "2.0.4"

Expand Down
12 changes: 9 additions & 3 deletions src/domain/team_id.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use derive_more::*;
use rand::Rng;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};

use std::sync::atomic::{AtomicI64, Ordering};

#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TeamId(i64);

lazy_static! {
static ref NEXT_ID: AtomicI64 = AtomicI64::new(0);
}

impl TeamId {
pub fn new() -> Self {
let mut rng = rand::thread_rng();
TeamId(rng.gen::<i64>())
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
TeamId(id)
}
}

0 comments on commit abf3a6e

Please sign in to comment.