From 07f3e80f3e901956540769cebb03eca009d8738f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 27 Jul 2020 01:19:03 +0100 Subject: [PATCH] reorganise global.rs --- src/global.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/global.rs b/src/global.rs index d78a3fce..1dadf397 100644 --- a/src/global.rs +++ b/src/global.rs @@ -61,8 +61,6 @@ pub struct TokenRegistry { id : PhantomData, } -// ---------- Token Table API ---------- - #[derive(Clone,Debug)] pub struct InstanceAccessDetails { pub gref : InstanceRef, @@ -75,20 +73,6 @@ pub struct InstanceAccess<'i, Id> { pub i : InstanceAccessDetails, } -pub type TokenTable = HashMap>; - -pub trait AccessId : Copy + Clone + 'static { - fn global_tokens(_:PrivateCaller) -> &'static RwLock>; - fn tokens_registry(ig: &mut Instance, _:PrivateCaller) - -> &mut TokenRegistry; - 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 From> for InstanceLockError { fn from(_: PoisonError) -> 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 for RawToken { @@ -353,7 +342,16 @@ impl InstanceGuard<'_> { } } -// ---------- Lookup and token API ---------- +// ---------- Tokens / TokenTable / AccessId ---------- + +pub type TokenTable = HashMap>; + +pub trait AccessId : Copy + Clone + 'static { + fn global_tokens(_:PrivateCaller) -> &'static RwLock>; + fn tokens_registry(ig: &mut Instance, _:PrivateCaller) + -> &mut TokenRegistry; + const ERROR : OnlineError; +} impl AccessId for PlayerId { const ERROR : OnlineError = NoPlayer; -- 2.30.2