mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 14:15:24 +00:00
merge impl-v2: server
This commit is contained in:
21
server/src/id.rs
Normal file
21
server/src/id.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
/// A unique identifier, not guaranteed to be generated in any order.
|
||||
pub type Id = usize;
|
||||
|
||||
lazy_static! {
|
||||
static ref LAST_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
}
|
||||
|
||||
/// Generate a new ID, which has no defined ordering.
|
||||
pub fn get_id() -> Id {
|
||||
LAST_ID.fetch_add(1, Ordering::SeqCst)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_gives_unique_numbers() {
|
||||
let a = get_id();
|
||||
let b = get_id();
|
||||
|
||||
assert!(a != b);
|
||||
}
|
||||
Reference in New Issue
Block a user