#[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()
}
}
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
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(),
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
H::Vacant(ve) => {
debug!("loaded shape {} {}", libname, item_name);
ve.insert(idata);
- },
+ }
};
}
}
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, .. }|
.collect::<Result<Vec<_>, LLE>>()?;
Box::new(results.into_iter())
- },
+
+ }
})
}
}
#[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] {
/// 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!()))? ))
//---------- 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 {
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;
// 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;
#[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! {
#[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 ----------
#[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>,
}
}
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 {
TPS::AllLocal => {
// abuse that usernames are not encoded
scope_glob(AS::Unix { user: "*".into() })
- },
+ }
}
}
}
}
#[typetag::serde(tag="access")]
- pub trait PlayerAccessSpec : Debug + Sync + Send {
+ pub trait PlayerAccessSpec: Debug + Sync + Send {
fn override_token(&self) -> Option<&RawToken> {
None
}
};
command.args(&["-f", &user]);
nwtemplates::render("token-unix.tera", &data)
- },
+ }
_ => {
#[derive(Debug,Serialize)]
struct Data<'r> {
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()
]}
#[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 {
}
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);
}
impl Display for UpdateId {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- Display::fmt(&self.0,f)
+ Display::fmt(&self.0, f)
}
}