From: Ian Jackson Date: Mon, 27 Jul 2020 00:19:03 +0000 (+0100) Subject: reorganise global.rs X-Git-Tag: otter-0.2.0~1229 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=07f3e80f3e901956540769cebb03eca009d8738f;p=otter.git reorganise global.rs --- 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;