From: Ian Jackson Date: Thu, 18 Jun 2020 00:15:12 +0000 (+0100) Subject: switch to slotmap X-Git-Tag: otter-0.2.0~1577 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=058e45793e38a98e80b590dd3fe9b24b94cd581f;p=otter.git switch to slotmap --- diff --git a/Cargo.lock.example b/Cargo.lock.example index 00a13a1e..cd51d6d9 100644 --- a/Cargo.lock.example +++ b/Cargo.lock.example @@ -338,12 +338,12 @@ name = "game" version = "0.0.1" dependencies = [ "anyhow", - "handy", "lazy_static", "rocket", "rocket_contrib", "serde", "serde_json", + "slotmap", "thiserror", ] @@ -394,10 +394,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "handy" -version = "0.1.3" - [[package]] name = "hermit-abi" version = "0.1.14" @@ -1065,6 +1061,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "slotmap" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c46a3482db8f247956e464d783693ece164ca056e6e67563ee5505bdb86452cd" + [[package]] name = "slug" version = "0.1.4" diff --git a/Cargo.toml b/Cargo.toml index d7aba159..289fab34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,10 @@ thiserror = "1" serde = { version = "1", features = ["derive"] } serde_json = "1" -handy = "0.1" lazy_static = "1.0.0" +slotmap = "0.4" + rocket = "0.4" rocket_contrib = { version = "0.4", default-features=false, features=["tera_templates","helmet"] } diff --git a/src/global.rs b/src/global.rs index b21542ff..91ea10b1 100644 --- a/src/global.rs +++ b/src/global.rs @@ -2,8 +2,10 @@ use crate::imports::*; use lazy_static::lazy_static; -type UserId = TypedHandle; -type ClientId = TypedHandle; +slotmap::new_key_type!{ + struct UserId; + struct ClientId; +} #[derive(Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)] struct RawToken (String); @@ -21,8 +23,8 @@ struct User { struct Instance { /* game state goes here */ - users : TypedHandleMap, - clients : TypedHandleMap, + users : DenseSlotMap, + clients : DenseSlotMap, } #[derive(Clone)] diff --git a/src/imports.rs b/src/imports.rs index 71d99c71..627abb36 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -23,7 +23,7 @@ pub use rocket::request::{FromParam,FromRequest,FromFormValue,LenientForm}; pub use rocket::response::NamedFile; pub use rocket::response; -pub use handy::typed::{TypedHandle,TypedHandleMap}; +pub use slotmap::dense::{DenseSlotMap}; pub type E = anyhow::Error;