chiark / gitweb /
formatting, some from rustfmt (manually picked)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 6 Dec 2020 01:44:23 +0000 (01:44 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 6 Dec 2020 01:44:23 +0000 (01:44 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/shapelib.rs
src/slotmap-slot-idx.rs
src/spec.rs
src/sse.rs

index fc7e582afa283867876bd126673e53177a0b9b73..99674f900a452be4dced80c346290cf949c97f00 100644 (file)
@@ -287,7 +287,7 @@ impl Contents {
 
 #[typetag::serde(name="Lib")]
 impl PieceSpec for ItemSpec {
-  fn load(&self, _: usize) -> Result<Box<dyn Piece>,SpecError> {
+  fn load(&self, _: usize) -> Result<Box<dyn Piece>, 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::<Result<Vec<_>, 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<Coord> {
+  fn thresh_dragraise(&self, _pri: &PieceRenderInstructions) -> Option<Coord> {
     Some((self.diam * 0.5) as Coord)
   }
   fn bbox_approx(&self) -> [Pos;2] {
index c6580d1be5281e88d6642b82a81c359ac183628f..85254439fc9a5042097d817e84f853e267da0e0a 100644 (file)
@@ -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<Return> = Result<Return,Error>;
+type R<Return> = Result<Return, Error>;
 type ROk = R<()>;
 use self::Error::*;
 
 fn error(line: u32) -> Error { Unexpected(TryFrom::try_from(line).unwrap()) }
 fn u<T>(line: u32) -> R<T> { Err(error(line)) }
 
-type Imp = Impossible<(),Error>;
+type Imp = Impossible<(), Error>;
 type RI = R<Imp>;
 
 impl Serializer for &mut MainExtractor {
   type Ok = ();
   type Error = Error;
-  
+
   type SerializeStruct = Self;
 
   type SerializeMap           = Imp;
index b8948ed883718d87e11da659aa26a3563dd47cf5..41f95c52f14b3a1c20de01c34f8eef64f630952c 100644 (file)
@@ -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<T> (pub [T; 2]);
+pub struct PosC<T>(pub [T; 2]);
 pub type Pos = PosC<Coord>;
 
 #[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<Pos>,
-  pub pieces : Vec<PiecesSpec>,
+  pub table_size: Option<Pos>,
+  pub pieces: Vec<PiecesSpec>,
   pub table_colour: Option<ColourSpec>,
 }
 
-#[derive(Debug,Serialize,Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
 pub struct PiecesSpec {
-  pub pos : Option<Pos>,
-  pub posd : Option<Pos>,
-  pub count : Option<u32>,
-  pub face : Option<FaceId>,
+  pub pos: Option<Pos>,
+  pub posd: Option<Pos>,
+  pub count: Option<u32>,
+  pub face: Option<FaceId>,
   pub pinned: Option<bool>,
   #[serde(flatten)]
-  pub info : Box<dyn PieceSpec>,
+  pub info: Box<dyn PieceSpec>,
 }
 
 //---------- Piece specs ----------
@@ -158,15 +160,15 @@ pub mod piece_specs {
   #[derive(Debug,Serialize,Deserialize)]
   pub struct Disc {
     pub itemname: Option<String>,
-    pub diam : Coord,
-    pub faces : IndexVec<FaceId,ColourSpec>,
+    pub diam: Coord,
+    pub faces: IndexVec<FaceId, ColourSpec>,
   }
 
   #[derive(Debug,Serialize,Deserialize)]
   pub struct Square {
     pub itemname: Option<String>,
-    pub size : Vec<Coord>,
-    pub faces : IndexVec<FaceId,ColourSpec>,
+    pub size: Vec<Coord>,
+    pub faces: IndexVec<FaceId, ColourSpec>,
   }
 
 }
@@ -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()
       ]}
index 788e56777276b762f2631591db52c925ce610167..36b1800d8d2a7f67f6246604a6d047556136f17e 100644 (file)
@@ -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<usize,io::Error> {
+  fn read(&mut self, orig_buf: &mut [u8]) -> Result<usize, io::Error> {
     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)
   }
 }