impl<X> From<PoisonError<X>> for OnlineError {
fn from(_: PoisonError<X>) -> OnlineError { GameCorrupted }
}
+
+
+pub trait ById {
+ type Id;
+ type Entry;
+ #[throws(OE)]
+ fn byid(&self, t: Self::Id) -> &Self::Entry;
+}
+
+impl<I:AccessId+slotmap::Key, T> ById for DenseSlotMap<I,T> {
+ type Id = I;
+ type Entry = T;
+ fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> {
+ self.get(t).ok_or(<I as AccessId>::ERROR)
+ }
+}
+impl<I:AccessId+slotmap::Key, T> ById for SecondarySlotMap<I,T> {
+ type Id = I;
+ type Entry = T;
+ fn byid(&self, t: Self::Id) -> Result<&Self::Entry, OE> {
+ self.get(t).ok_or(<I as AccessId>::ERROR)
+ }
+}
}
impl AccessId for PlayerId {
- fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.players }
const ERROR : OnlineError = NoPlayer;
+ fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.players }
}
impl AccessId for ClientId {
- fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.clients }
const ERROR : OnlineError = NoClient;
+ fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.clients }
}
pub fn lookup_token<Id : AccessId>(s : &str)
let content = {
let mut ig = iad.g.lock()?;
let _g = &mut ig.gs;
- let cl = ig.clients.get(client).ok_or(NoClient)?;
+ let cl = ig.clients.byid(client)?;
let player = cl.player;
let ami = iad.g.clone();
- let log = &ig.updates.get(player).ok_or(NoPlayer)?.log;
+ let log = &ig.updates.byid(player)?.log;
let to_send = match log.into_iter().rev()
.find(|(_,update)| update.gen < gen) {