From: Ian Jackson Date: Sun, 14 Mar 2021 17:03:12 +0000 (+0000) Subject: at: impl PieceSpecForOp for &mut too X-Git-Tag: otter-0.4.0~70 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=121aba5fef135838ae22ec68dac0d4f3c58bc790;p=otter.git at: impl PieceSpecForOp for &mut too Signed-off-by: Ian Jackson --- diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index bf5d2033..4fd4866a 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -438,27 +438,35 @@ impl PieceSpecForOp for &String { } type PuUp<'pcs, PI> = (&'pcs mut Pieces, PI); -impl PieceSpecForOp for PuUp<'_, PI> { - type PI = PI; - fn id(&self) -> &str { &self.0[self.1].id } - fn for_update(&mut self) -> Option<&mut PieceInfo> { - Some(&mut self.0[self.1]) - } -} - #[derive(Debug)] /// Synchronise after op but before any ungrab. pub struct PuSynch(T); -impl PieceSpecForOp for PuSynch> { - type PI = PI; - fn id(&self) -> &str { self.0.id() } - fn for_update(&mut self) -> Option<&mut PieceInfo> { - self.0.for_update() - } - fn for_synch(&mut self) -> Option<&mut Pieces> { - Some(self.0.0) + +macro_rules! impl_PieceSpecForOp { + ($($amp:tt $mut:tt)?) => { + + impl PieceSpecForOp for $($amp $mut)? PuUp<'_, PI> { + type PI = PI; + fn id(&self) -> &str { &self.0[self.1].id } + fn for_update(&mut self) -> Option<&mut PieceInfo> { + Some(&mut self.0[self.1]) + } + } + + impl PieceSpecForOp for PuSynch<$($amp $mut)? PuUp<'_,PI>> { + type PI = PI; + fn id(&self) -> &str { self.0.id() } + fn for_update(&mut self) -> Option<&mut PieceInfo> { + self.0.for_update() + } + fn for_synch(&mut self) -> Option<&mut Pieces> { + Some(self.0.0) + } + } } } +impl_PieceSpecForOp!{} +impl_PieceSpecForOp!{&mut} #[derive(Debug,Copy,Clone)] pub enum GrabHow { Raw, Grab, Ungrab, With }