From 0342df0ff4d3b9d5f3e33c7aae04619c74c2f2aa Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 1 Feb 2021 00:36:12 +0000 Subject: [PATCH] style: Make commands::* not global, type aliases, etc. Signed-off-by: Ian Jackson --- daemon/cmdlistener.rs | 1 + src/accounts.rs | 2 +- src/bin/otter.rs | 5 +++-- src/commands.rs | 2 ++ src/global.rs | 9 ++++----- src/imports.rs | 2 +- src/mgmtchannel.rs | 1 + src/shapelib.rs | 2 +- src/spec.rs | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 4cb64c6f..36ed00ce 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -5,6 +5,7 @@ // management API implementation use super::*; +use otter::commands::*; use authproofs::*; diff --git a/src/accounts.rs b/src/accounts.rs index 7775a2dd..8a37e6fa 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -518,7 +518,7 @@ pub mod loaded_acl { Err(if needed & test_existence != 0 { P::NOT_FOUND } else { - MgmtError::AuthorisationError + ME::AuthorisationError })? } } diff --git a/src/bin/otter.rs b/src/bin/otter.rs index b4589591..432ee1ef 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -12,6 +12,7 @@ use argparse::{self,ArgumentParser,action::{TypedAction,ParseResult}}; use argparse::action::{Action,IFlagAction,IArgAction}; use derive_more::Display; +use otter::commands::*; use otter::imports::*; type APE = ArgumentParseError; @@ -596,10 +597,10 @@ impl ConnForGame { */ #[throws(AE)] fn get_pieces(&mut self) -> Vec { - let insns = vec![ MgmtGameInstruction::ListPieces ]; + let insns = vec![ MGI::ListPieces ]; let mut responses = self.alter_game(insns, None)?; match responses.as_mut_slice() { - [MgmtGameResponse::Pieces(pieces)] => return mem::take(pieces), + [MGR::Pieces(pieces)] => return mem::take(pieces), wat => Err(anyhow!("ListPieces => {:?}", &wat))?, } } diff --git a/src/commands.rs b/src/commands.rs index 31a5c85e..faa2f92e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -198,6 +198,8 @@ impl From for MgmtError { } } +from_instance_lock_error!{MgmtError} + impl AccessTokenInfo { pub fn report(self) -> Vec { vec![ diff --git a/src/global.rs b/src/global.rs index b8ba07a8..2e115715 100644 --- a/src/global.rs +++ b/src/global.rs @@ -225,7 +225,6 @@ display_as_debug!{InstanceLockError} impl From> for InstanceLockError { fn from(_: PoisonError) -> Self { Self::GameCorrupted } } -from_instance_lock_error!{MgmtError} pub struct PrivateCaller(()); // outsiders cannot construct this @@ -319,7 +318,7 @@ impl Instance { use hash_map::Entry::*; let entry = match entry { Vacant(ve) => ve, - Occupied(_) => throw!(MgmtError::AlreadyExists), + Occupied(_) => throw!(ME::AlreadyExists), }; ig.save_access_now()?; @@ -340,7 +339,7 @@ impl Instance { Unauthorised::of( games_table .get(name) - .ok_or(MgmtError::GameNotFound)? + .ok_or(ME::GameNotFound)? .clone() .into() ) @@ -540,7 +539,7 @@ impl<'ig> InstanceGuard<'ig> { // we have a thing to serialise with the player in it self.check_new_nick(&gnew.nick)?; if self.c.g.iplayers.values().any(|r| r.ipl.acctid == inew.acctid) { - Err(MgmtError::AlreadyExists)?; + Err(ME::AlreadyExists)?; } let player = self.c.g.gs.players.insert(gnew); let u = PlayerUpdates::new_begin(&self.c.g.gs).new(); @@ -575,7 +574,7 @@ impl<'ig> InstanceGuard<'ig> { #[throws(MgmtError)] pub fn check_new_nick(&mut self, new_nick: &str) { if self.c.g.gs.players.values().any(|old| old.nick == new_nick) { - Err(MgmtError::NickCollision)?; + Err(ME::NickCollision)?; } } diff --git a/src/imports.rs b/src/imports.rs index 98d3fbf5..f97558ee 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -85,7 +85,7 @@ pub use crate::accounts::loaded_acl::{self, EffectiveACL, LoadedAcl, PermSet}; pub use crate::accounts::*; pub use crate::authproofs::{self, Authorisation, Unauthorised}; pub use crate::authproofs::AuthorisationSuperuser; -pub use crate::commands::*; +pub use crate::commands::{AccessTokenInfo, AccessTokenReport, MgmtError}; pub use crate::config::*; pub use crate::debugreader::DebugReader; pub use crate::error::*; diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 2f629f7a..dfacb387 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -3,6 +3,7 @@ // There is NO WARRANTY. use crate::imports::*; +use crate::commands::*; #[derive(Debug,Error)] pub enum MgmtChannelReadError { diff --git a/src/shapelib.rs b/src/shapelib.rs index f85ab52a..40cc898d 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -251,7 +251,7 @@ impl Contents { #[throws(MgmtError)] pub fn list_glob(&self, pat: &str) -> Vec { - let pat = glob::Pattern::new(pat).map_err(|pe| MgmtError::BadGlob { + let pat = glob::Pattern::new(pat).map_err(|pe| ME::BadGlob { pat: pat.to_string(), msg: pe.msg.to_string() })?; let mut out = vec![]; for (k,v) in &self.items { diff --git a/src/spec.rs b/src/spec.rs index bc440179..9cabe247 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -340,7 +340,7 @@ pub mod implementation { impl loaded_acl::Perm for TablePermission { type Auth = InstanceName; const TEST_EXISTENCE: Self = TablePermission::TestExistence; - const NOT_FOUND: MgmtError = MgmtError::GameNotFound; + const NOT_FOUND: MgmtError = ME::GameNotFound; } impl TablePlayerSpec { -- 2.30.2