From: Ian Jackson Date: Sat, 13 Mar 2021 18:12:01 +0000 (+0000) Subject: at-otter: Introduce Pieces and PiecesSlice X-Git-Tag: otter-0.4.0~107 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7e2ef25a241c5ccaff3727472d403ce8141327e6;p=otter.git at-otter: Introduce Pieces and PiecesSlice Signed-off-by: Ian Jackson --- diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index fd4c9402..f9f8dbfd 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -209,6 +209,9 @@ mod pi { } pub use pi::*; +type Pieces = IndexVec>; +type PiecesSlice = IndexSlice]>; + #[derive(Debug,Clone)] pub struct PieceInfo { id: String, @@ -218,7 +221,7 @@ pub struct PieceInfo { impl Session { #[throws(AE)] - fn pieces(&self) -> IndexVec> { + fn pieces(&self) -> Pieces { let pieces = self.dom .element("#pieces_marker") .unwrap().next_siblings() @@ -320,7 +323,7 @@ impl Session { PI: Idx, F: FnMut(&mut Session, Generation, &str, &JsV), > (&mut self, - mut pieces: Option<&mut IndexVec>>, + mut pieces: Option<&mut Pieces>, ef: Option<&mut dyn FnMut(&mut Session, Generation, &JsV) -> Result<(), AE>>, mut f: F) @@ -346,7 +349,7 @@ impl Session { } #[throws(AE)] - fn synchu(&mut self, pieces: &mut IndexVec>) { + fn synchu(&mut self, pieces: &mut Pieces) { self.synchx(Some(pieces), None, |_session, _gen, _k, _v| ())?; } @@ -358,7 +361,7 @@ impl Session { pub fn update_update_pieces( nick: &str, - pieces: &mut IndexVec>, + pieces: &mut Pieces, k: &str, v: &JsV ) { if k != "Piece" { return } @@ -471,9 +474,7 @@ impl Ctx { "wrc": "Unpredictable", }))?; - fn find_pawns(pieces: &IndexSlice]>) - -> [PI; 2] - { + fn find_pawns(pieces: &PiecesSlice) -> [PI; 2] { let mut pawns = pieces.iter_enumerated() .filter(|(i,p)| p.info["desc"].as_str().unwrap().ends_with(" pawn")) .map(|(i,_)| i)