merge impl-v2: server

This commit is contained in:
Lucien Greathouse
2018-06-10 22:59:04 -07:00
parent e30545c132
commit ec1f9bd706
35 changed files with 1643 additions and 1207 deletions

21
server/src/id.rs Normal file
View 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);
}