mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 04:51:47 +00:00
merge impl-v2: server
This commit is contained in:
parent
e30545c132
commit
ec1f9bd706
35 changed files with 1643 additions and 1207 deletions
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue