chiark / gitweb /
reorganise global.rs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 27 Jul 2020 00:19:03 +0000 (01:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 27 Jul 2020 00:19:03 +0000 (01:19 +0100)
src/global.rs

index d78a3fcec118863eff4818dc5dd5a5899afb8a98..1dadf3971c4aa81037e021e41b3acd595e2de60d 100644 (file)
@@ -61,8 +61,6 @@ pub struct TokenRegistry<Id: AccessId> {
   id : PhantomData<Id>,
 }
 
-// ---------- Token Table API ----------
-
 #[derive(Clone,Debug)]
 pub struct InstanceAccessDetails<Id> {
   pub gref : InstanceRef,
@@ -75,20 +73,6 @@ pub struct InstanceAccess<'i, Id> {
   pub i : InstanceAccessDetails<Id>,
 }
 
-pub type TokenTable<Id> = HashMap<RawToken, InstanceAccessDetails<Id>>;
-
-pub trait AccessId : Copy + Clone + 'static {
-  fn global_tokens(_:PrivateCaller) -> &'static RwLock<TokenTable<Self>>;
-  fn tokens_registry(ig: &mut Instance, _:PrivateCaller)
-                     -> &mut TokenRegistry<Self>;
-  const ERROR : OnlineError;
-}
-
-pub struct PrivateCaller(());
-// outsiders cannot construct this
-// workaround for inability to have private trait methods
-const PRIVATE_Y : PrivateCaller = PrivateCaller(());
-
 // ========== internal data structures ==========
 
 lazy_static! {
@@ -120,6 +104,11 @@ impl<X> From<PoisonError<X>> for InstanceLockError {
   fn from(_: PoisonError<X>) -> Self { Self::GameCorrupted }
 }
 
+pub struct PrivateCaller(());
+// outsiders cannot construct this
+// workaround for inability to have private trait methods
+const PRIVATE_Y : PrivateCaller = PrivateCaller(());
+
 // ========== implementations ==========
 
 impl Borrow<str> for RawToken {
@@ -353,7 +342,16 @@ impl InstanceGuard<'_> {
   }
 }
 
-// ---------- Lookup and token API ----------
+// ---------- Tokens / TokenTable / AccessId ----------
+
+pub type TokenTable<Id> = HashMap<RawToken, InstanceAccessDetails<Id>>;
+
+pub trait AccessId : Copy + Clone + 'static {
+  fn global_tokens(_:PrivateCaller) -> &'static RwLock<TokenTable<Self>>;
+  fn tokens_registry(ig: &mut Instance, _:PrivateCaller)
+                     -> &mut TokenRegistry<Self>;
+  const ERROR : OnlineError;
+}
 
 impl AccessId for PlayerId {
   const ERROR : OnlineError = NoPlayer;