From c39a572e05a3af71014d0431dc13017cae4052a1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 6 Dec 2020 01:44:23 +0000 Subject: [PATCH] formatting, some from rustfmt (manually picked) Signed-off-by: Ian Jackson --- src/shapelib.rs | 20 +++++++------- src/slotmap-slot-idx.rs | 14 +++++----- src/spec.rs | 60 +++++++++++++++++++++-------------------- src/sse.rs | 20 +++++++------- 4 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/shapelib.rs b/src/shapelib.rs index fc7e582a..99674f90 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -287,7 +287,7 @@ impl Contents { #[typetag::serde(name="Lib")] impl PieceSpec for ItemSpec { - fn load(&self, _: usize) -> Result,SpecError> { + fn load(&self, _: usize) -> Result, SpecError> { self.load() } } @@ -315,7 +315,7 @@ fn resolve_inherit<'r>(depth: u8, groups: &toml::value::Table, let group = group.as_table().ok_or_else(|| LLE::ExpectedTable(gp()))?; let parent_name = match group.get("inherit") { - None => { return Cow::Borrowed(group) }, + None => { return Cow::Borrowed(group) } Some(p) => p, }; let parent_name = parent_name @@ -340,7 +340,7 @@ fn load_catalogue(libname: &str, dirname: &str, toml_path: &str) -> Contents { let mut f = BufReader::new(f); let mut s = String::new(); f.read_to_string(&mut s).map_err(ioe)?; - let toplevel : toml::Value = s.parse()?; + let toplevel: toml::Value = s.parse()?; let mut l = Contents { libname: libname.to_string(), items: HashMap::new(), @@ -355,7 +355,7 @@ fn load_catalogue(libname: &str, dirname: &str, toml_path: &str) -> Contents { for (groupname, gdefn) in groups { let gdefn = resolve_inherit(INHERIT_DEPTH_LIMIT, &groups, groupname, gdefn)?; - let gdefn : GroupDefn = TV::Table(gdefn.into_owned()).try_into()?; + let gdefn: GroupDefn = TV::Table(gdefn.into_owned()).try_into()?; let d = GroupDetails { size: gdefn.d.size.iter().map(|s| s * gdefn.d.scale).collect(), ..gdefn.d @@ -381,7 +381,7 @@ fn load_catalogue(libname: &str, dirname: &str, toml_path: &str) -> Contents { H::Vacant(ve) => { debug!("loaded shape {} {}", libname, item_name); ve.insert(idata); - }, + } }; } } @@ -445,7 +445,7 @@ impl Config1 { let results = glob::glob_with(pat, glob::MatchOptions { require_literal_separator: true, require_literal_leading_dot: true, - .. Default::default() + ..default() }) .map_err( |glob::PatternError { pos, msg, .. }| @@ -455,7 +455,8 @@ impl Config1 { .collect::, LLE>>()?; Box::new(results.into_iter()) - }, + + } }) } } @@ -479,12 +480,11 @@ pub struct Circle { pub diam: f64 } #[typetag::serde(name="Circle")] impl Outline for Circle { #[throws(IE)] - fn surround_path(&self, _pri : &PieceRenderInstructions) -> Html { + fn surround_path(&self, _pri: &PieceRenderInstructions) -> Html { svg_circle_path(self.diam * SELECT_SCALE)? } #[throws(IE)] - fn thresh_dragraise(&self, _pri : &PieceRenderInstructions) - -> Option { + fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) -> Option { Some((self.diam * 0.5) as Coord) } fn bbox_approx(&self) -> [Pos;2] { diff --git a/src/slotmap-slot-idx.rs b/src/slotmap-slot-idx.rs index c6580d1b..85254439 100644 --- a/src/slotmap-slot-idx.rs +++ b/src/slotmap-slot-idx.rs @@ -46,8 +46,8 @@ impl KeyDataExt for slotmap::KeyData { /// Fails if the `slotmap::KeyData` `serde::ser::Serialize` /// representation has changed too much. Should not be able to fail /// otherwise. -pub fn keydata_extract(key : slotmap::KeyData) -> Result<(u32, u32), Error> { - let mut m : MainExtractor = std::default::Default::default(); +pub fn keydata_extract(key: slotmap::KeyData) -> Result<(u32, u32), Error> { + let mut m: MainExtractor = std::default::Default::default(); key.serialize(&mut m)?; Ok(( m.idx .ok_or(error(line!()))?, m.version.ok_or(error(line!()))? )) @@ -67,10 +67,10 @@ impl std::error::Error for Error { } //---------- implementation. avert your eyes ---------- -use serde::ser::{self,*}; -use std::line; use std::convert::TryFrom; use std::fmt; +use std::line; +use serde::ser::{self, *}; #[derive(Default)] struct MainExtractor { @@ -80,20 +80,20 @@ struct MainExtractor { struct ValueExtractor; -type R = Result; +type R = Result; type ROk = R<()>; use self::Error::*; fn error(line: u32) -> Error { Unexpected(TryFrom::try_from(line).unwrap()) } fn u(line: u32) -> R { Err(error(line)) } -type Imp = Impossible<(),Error>; +type Imp = Impossible<(), Error>; type RI = R; impl Serializer for &mut MainExtractor { type Ok = (); type Error = Error; - + type SerializeStruct = Self; type SerializeMap = Imp; diff --git a/src/spec.rs b/src/spec.rs index b8948ed8..41f95c52 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -4,17 +4,19 @@ // game specs -use serde::{Serialize,Deserialize}; -use fehler::throws; -use index_vec::{define_index_type,IndexVec}; -use crate::gamestate::PieceSpec; -use std::fmt::Debug; use std::collections::hash_set::HashSet; +use std::fmt::Debug; +use std::hash::Hash; + +use fehler::throws; +use index_vec::{define_index_type, IndexVec}; +use num_derive::{FromPrimitive, ToPrimitive}; +use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::error::display_as_debug; + use crate::accounts::AccountName; -use std::hash::Hash; -use num_derive::{ToPrimitive, FromPrimitive}; +use crate::error::display_as_debug; +use crate::gamestate::PieceSpec; pub use implementation::PlayerAccessSpec; @@ -27,12 +29,12 @@ pub type Coord = isize; #[derive(Clone,Copy,Debug,Serialize,Deserialize,Hash)] #[derive(Eq,PartialEq,Ord,PartialOrd)] #[serde(transparent)] -pub struct PosC (pub [T; 2]); +pub struct PosC(pub [T; 2]); pub type Pos = PosC; #[derive(Clone,Eq,PartialEq,Ord,PartialOrd,Hash,Serialize,Deserialize)] #[serde(transparent)] -pub struct RawToken (pub String); +pub struct RawToken(pub String); pub type RawFaceId = u8; define_index_type! { @@ -133,20 +135,20 @@ pub struct UrlOnStdout; #[derive(Debug,Serialize,Deserialize)] pub struct GameSpec { - pub table_size : Option, - pub pieces : Vec, + pub table_size: Option, + pub pieces: Vec, pub table_colour: Option, } -#[derive(Debug,Serialize,Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct PiecesSpec { - pub pos : Option, - pub posd : Option, - pub count : Option, - pub face : Option, + pub pos: Option, + pub posd: Option, + pub count: Option, + pub face: Option, pub pinned: Option, #[serde(flatten)] - pub info : Box, + pub info: Box, } //---------- Piece specs ---------- @@ -158,15 +160,15 @@ pub mod piece_specs { #[derive(Debug,Serialize,Deserialize)] pub struct Disc { pub itemname: Option, - pub diam : Coord, - pub faces : IndexVec, + pub diam: Coord, + pub faces: IndexVec, } #[derive(Debug,Serialize,Deserialize)] pub struct Square { pub itemname: Option, - pub size : Vec, - pub faces : IndexVec, + pub size: Vec, + pub faces: IndexVec, } } @@ -285,8 +287,8 @@ 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 TEST_EXISTENCE: Self = TablePermission::TestExistence; + const NOT_FOUND: MgmtError = MgmtError::GameNotFound; } impl TablePlayerSpec { @@ -303,7 +305,7 @@ pub mod implementation { TPS::AllLocal => { // abuse that usernames are not encoded scope_glob(AS::Unix { user: "*".into() }) - }, + } } } } @@ -323,7 +325,7 @@ pub mod implementation { } #[typetag::serde(tag="access")] - pub trait PlayerAccessSpec : Debug + Sync + Send { + pub trait PlayerAccessSpec: Debug + Sync + Send { fn override_token(&self) -> Option<&RawToken> { None } @@ -440,7 +442,7 @@ pub mod implementation { }; command.args(&["-f", &user]); nwtemplates::render("token-unix.tera", &data) - }, + } _ => { #[derive(Debug,Serialize)] struct Data<'r> { @@ -481,10 +483,10 @@ pub mod implementation { let st = command .status() .with_context(|| format!("run sendmail ({})", sendmail))?; - if !st.success() { + if !st.success() { throw!(anyhow!("sendmail ({}) failed: {} ({})", sendmail, st, st)); } - + AccessTokenReport { lines: vec![ "Token sent by email.".to_string() ]} diff --git a/src/sse.rs b/src/sse.rs index 788e5677..36b1800d 100644 --- a/src/sse.rs +++ b/src/sse.rs @@ -15,17 +15,17 @@ use std::ops::Neg; #[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd)] #[derive(Serialize,Deserialize)] #[serde(transparent)] -pub struct UpdateId (i64); +pub struct UpdateId(i64); -const UPDATE_READER_SIZE : usize = 1024*32; -const UPDATE_MAX_FRAMING_SIZE : usize = 200; -const UPDATE_KEEPALIVE : Duration = Duration::from_secs(14); -const UPDATE_EXPIRE : Duration = Duration::from_secs(66); +const UPDATE_READER_SIZE: usize = 1024*32; +const UPDATE_MAX_FRAMING_SIZE: usize = 200; +const UPDATE_KEEPALIVE: Duration = Duration::from_secs(14); +const UPDATE_EXPIRE: Duration = Duration::from_secs(66); struct UpdateReaderWN { - player : PlayerId, - client : ClientId, - to_send : UpdateId, + player: PlayerId, + client: ClientId, + to_send: UpdateId, } struct UpdateReader { @@ -74,7 +74,7 @@ impl UpdateReaderWN { } impl Read for UpdateReader { - fn read(&mut self, orig_buf: &mut [u8]) -> Result { + fn read(&mut self, orig_buf: &mut [u8]) -> Result { if let Some(ref mut ending) = self.ending_send { return ending.read(orig_buf); } @@ -201,7 +201,7 @@ impl Neg for UpdateId { impl Display for UpdateId { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - Display::fmt(&self.0,f) + Display::fmt(&self.0, f) } } -- 2.30.2