mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Implement ID tracking, start dumping ideas into rbx_session
This commit is contained in:
parent
bb451bc4e9
commit
8d87d81f49
3 changed files with 149 additions and 0 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