chiark / gitweb /
switch to slotmap
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 18 Jun 2020 00:15:12 +0000 (01:15 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 18 Jun 2020 00:15:12 +0000 (01:15 +0100)
Cargo.lock.example
Cargo.toml
src/global.rs
src/imports.rs

index 00a13a1e1ba4007866b8e2256425c3d9bee594de..cd51d6d9237207b6a8d835206fb0e457da5a0f6a 100644 (file)
@@ -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"
index d7aba15934db4ad9baf9c7431caa370f52f32787..289fab34a8b2d96ae22934ef4691905d36d6ad3b 100644 (file)
@@ -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"] }
 
index b21542ffbf46c2835094f86f2240f947db4bb881..91ea10b16638e2cacde937450cf91d21c89160d3 100644 (file)
@@ -2,8 +2,10 @@
 use crate::imports::*;
 use lazy_static::lazy_static;
 
-type UserId = TypedHandle<User>;
-type ClientId = TypedHandle<Client>;
+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<User>,
-  clients : TypedHandleMap<Client>,
+  users : DenseSlotMap<UserId,User>,
+  clients : DenseSlotMap<ClientId,Client>,
 }
 
 #[derive(Clone)]
index 71d99c716a6af3aab810faff152e29569643ea1c..627abb36bbc92ff4e229b1a1e9174041fc89266f 100644 (file)
@@ -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;