chiark / gitweb /
split PieceSpecLoaded
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 18 Apr 2022 10:07:55 +0000 (11:07 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 18 Apr 2022 12:15:05 +0000 (13:15 +0100)
We are goint to want to add a field to only the non-inert version, so
this generic is not applicable any more.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/clock.rs
src/currency.rs
src/deck.rs
src/dice.rs
src/gamestate.rs
src/hand.rs
src/pcaliases.rs
src/pieces.rs
src/shapelib.rs

index dd59a4a8ece323e3a978ada0b254664267f26e81..77468fbfd7aa6236f7142152db782fc1c479fbda 100644 (file)
@@ -1110,7 +1110,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           last_released: default(),
           rotateable: true,
         };
-        let PieceSpecLoaded { p, occultable } =
+        let SpecLoaded { p, occultable } =
           info.load(piece_i as usize, &mut gpc, ig, SpecDepth::zero())?;
         if p.nfaces() <= face.into() {
           throw!(SpecError::FaceNotFound);
index 886a13b01428bb6f2e7836e18c9b88f7a1014cdf..2b1eb47f2e4b00ce9273f517abcf7f79231a09d5 100644 (file)
@@ -405,7 +405,7 @@ fn unprepared_update(piece: PieceId) -> UnpreparedUpdates {
 impl PieceSpec for Spec {
   #[throws(SpecError)]
   fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     if self.time <= 0 { throw!(SpecError::NegativeTimeout) }
 
     let clock = Clock {
@@ -414,7 +414,7 @@ impl PieceSpec for Spec {
 
     gpc.xdata_mut(|| State::new(self) )?;
 
-    PieceSpecLoaded {
+    SpecLoaded {
       p: Box::new(clock),
       occultable: None,
     }
index 03a1a02bfbadf2bac2390d97ec4b2b04b5007229..04dc23a0f2320bfa8329be687e3a3c6df5e3df6f 100644 (file)
@@ -42,12 +42,12 @@ pub struct Banknote {
 impl PieceSpec for Spec {
   #[throws(SpecError)]
   fn load(&self, _: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     gpc.rotateable = false;
 
     let Spec { ref image, ref currency, qty, min_unit } = *self;
 
-    let SpecLoaded { p: image, occultable:_ } =
+    let SpecLoadedInert { p: image, occultable:_ } =
       image.load_inert(ig, depth)?;
 
     let itemname = format!("currency-{}", image.itemname());
index d466eee30278612ca9738df30405d285e1e6a255..e31de48e30a7198b6817902fd4e677361429dd7e 100644 (file)
@@ -38,7 +38,7 @@ impl OutlineTrait for Deck {
 impl PieceSpec for piece_specs::Deck {
   #[throws(SpecError)]
   fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     let common = SimpleCommon {
       itemname: None,
       faces: self.faces.clone(),
@@ -68,7 +68,7 @@ impl PieceSpec for piece_specs::Deck {
       shape,
       label: self.label.load()?,
     }) as Box<dyn PieceTrait>;
-    PieceSpecLoaded {
+    SpecLoaded {
       p,
       occultable: None,
     }
index a43c3e634e0b35863afe75053b3e87a367212980..6c72dcc5ae609bfd23b38de6fc7b16fee9c55f7b 100644 (file)
@@ -99,10 +99,10 @@ struct OverlayTemplateContext<'c> {
 impl PieceSpec for Spec {
   #[throws(SpecError)]
   fn load(&self, _: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     gpc.rotateable = false;
 
-    let SpecLoaded { p: image, occultable: img_occultable } =
+    let SpecLoadedInert { p: image, occultable: img_occultable } =
       self.image.load_inert(ig, depth)?;
 
     let mut nfaces: Option<(RawFaceId, &'static str)> = None;
@@ -183,7 +183,7 @@ impl PieceSpec for Spec {
     let occultable = match (img_occultable, &self.occult) {
       (None, None) => None,
       (None, Some(occ)) => {
-        let SpecLoaded { p: image, occultable: image_occ_reload } =
+        let SpecLoadedInert { p: image, occultable: image_occ_reload } =
           self.image.load_inert(ig, depth)?;
 
         if image_occ_reload.is_some() {
@@ -221,7 +221,7 @@ impl PieceSpec for Spec {
       image: image.into()
     };
 
-    PieceSpecLoaded {
+    SpecLoaded {
       p: Box::new(die) as _,
       occultable,
     }
index 71d6af678239f25923ed7cf824d2614643543fa3..aa1a55a61b9358dc5faaa2202f4996a765b3db85 100644 (file)
@@ -280,11 +280,16 @@ pub struct ApiPieceOpArgs<'a> {
 }
 
 #[derive(Debug)]
-pub struct SpecLoaded<PT: ?Sized> {
-  pub p: Box<PT>,
+pub struct SpecLoaded {
+  pub p: Box<dyn PieceTrait>,
   pub occultable: PieceSpecLoadedOccultable,
 }
-pub type PieceSpecLoaded = SpecLoaded<dyn PieceTrait>;
+#[derive(Debug)]
+pub struct SpecLoadedInert {
+  pub p: Box<dyn InertPieceTrait>,
+  pub occultable: PieceSpecLoadedOccultable,
+}
+
 pub type PieceSpecLoadedOccultable =
   Option<(LOccultIlk, Arc<dyn InertPieceTrait>)>;
 
@@ -293,10 +298,10 @@ pub trait PieceSpec: Debug + Sync + Send + 'static {
   #[throws(SpecError)]
   fn count(&self, _pcaliases: &PieceAliases) -> usize { 1 }
   fn load(&self, i: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> Result<PieceSpecLoaded, SpecError>;
+          -> Result<SpecLoaded, SpecError>;
   /// Used when a piece wants to use another for its occulted form
   fn load_inert(&self, _ig: &Instance, _:SpecDepth)
-                -> Result<SpecLoaded<dyn InertPieceTrait>, SpecError> {
+                -> Result<SpecLoadedInert, SpecError> {
     throw!(SpE::ComplexPieceWhereInertRequired)
   }
 }
index 42994149c3b70d48ee8126b641fb588c48871bc1..5ed96ae0d0f89f41875646bfadd768739902c5d4 100644 (file)
@@ -88,7 +88,7 @@ impl OutlineTrait for Hand {
 
 impl piece_specs::OwnedCommon {
   #[throws(SpecError)]
-  fn load(&self, behaviour: Behaviour) -> PieceSpecLoaded {
+  fn load(&self, behaviour: Behaviour) -> SpecLoaded {
     let common = SimpleCommon {
       itemname: None,
       faces: index_vec![self.colour.clone()],
@@ -108,7 +108,7 @@ impl piece_specs::OwnedCommon {
       shape, behaviour,
       label: self.label.load()?,
     }) as Box<dyn PieceTrait>;
-    PieceSpecLoaded {
+    SpecLoaded {
       p,
       occultable: None,
     }
@@ -119,7 +119,7 @@ impl piece_specs::OwnedCommon {
 impl PieceSpec for piece_specs::Hand {
   #[throws(SpecError)]
   fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     gpc.moveable = PieceMoveable::IfWresting;
     gpc.rotateable = false;
     self.c.load(Behaviour::Hand)?
@@ -130,7 +130,7 @@ impl PieceSpec for piece_specs::Hand {
 impl PieceSpec for piece_specs::PlayerLabel {
   #[throws(SpecError)]
   fn load(&self, _: usize, _: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     self.c.load(Behaviour::PlayerLabel)?
   }
 }
index 9d4f30eea5ee75ed92d5ba6d4c931360deec3584..e123adb84745fbe308357e14e86848ec8b4cc43c 100644 (file)
@@ -65,14 +65,13 @@ impl PieceSpec for Alias {
   }
   #[throws(SpecError)]
   fn load(&self, i: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     let r = self.resolve(&ig.pcaliases)?
       .load(i, gpc, ig, self.new_depth(depth)?)?;
     r
   }
   #[throws(SpecError)]
-  fn load_inert(&self, ig: &Instance, depth: SpecDepth)
-                 -> SpecLoaded<dyn InertPieceTrait> {
+  fn load_inert(&self, ig: &Instance, depth: SpecDepth) -> SpecLoadedInert {
     self.resolve(&ig.pcaliases)?.load_inert(ig, self.new_depth(depth)?)?
   }
 }
index e06d8e399027cbd234bc4e2862fb0356b42bdf76..b353037a9ff026ef25d800c817c8c38b13e6f2c5 100644 (file)
@@ -354,17 +354,16 @@ macro_rules! impl_PieceSpec_for_SimplePieceSpec { { $ty:ty } => {
   impl PieceSpec for $ty {
     #[throws(SpecError)]
     fn load(&self, _: usize, _: &mut GPiece, _ig: &Instance, _:SpecDepth)
-            -> PieceSpecLoaded {
-      PieceSpecLoaded {
+            -> SpecLoaded {
+      SpecLoaded {
         p: Box::new(self.load_raw()?.0),
         occultable: None,
       }
     }
 
     #[throws(SpecError)]
-    fn load_inert(&self, _ig: &Instance, _:SpecDepth)
-                  -> SpecLoaded<dyn InertPieceTrait> {
-      SpecLoaded {
+    fn load_inert(&self, _ig: &Instance, _:SpecDepth) -> SpecLoadedInert {
+      SpecLoadedInert {
         p: Box::new(self.load_raw()?.0) as _,
         occultable: None
       }
index b075722cee80e8e94a7855177eac0b0872f58e74..3eee455c9ebb4802a49172449f7e309387a84969 100644 (file)
@@ -488,9 +488,9 @@ impl<'ig> AllRegistries<'ig> {
 
 pub type ItemSpecLoaded = (Box<Item>, PieceSpecLoadedOccultable);
 
-impl From<ItemSpecLoaded> for PieceSpecLoaded {
-  fn from((p, occultable):  ItemSpecLoaded) -> PieceSpecLoaded {
-    PieceSpecLoaded {
+impl From<ItemSpecLoaded> for SpecLoaded {
+  fn from((p, occultable):  ItemSpecLoaded) -> SpecLoaded {
+    SpecLoaded {
       p,
       occultable,
     }
@@ -654,14 +654,13 @@ impl Contents {
 impl PieceSpec for ItemSpec {
   #[throws(SpecError)]
   fn load(&self, _: usize, _: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> PieceSpecLoaded {
+          -> SpecLoaded {
     self.find_load(ig,depth)?.into()
   }
   #[throws(SpecError)]
-  fn load_inert(&self, ig: &Instance, depth: SpecDepth)
-                -> SpecLoaded<dyn InertPieceTrait> {
+  fn load_inert(&self, ig: &Instance, depth: SpecDepth) -> SpecLoadedInert {
     let (p, occultable) = self.find_load(ig,depth)?;
-    SpecLoaded { p: p as _, occultable }
+    SpecLoadedInert { p: p as _, occultable }
   }
 }
 
@@ -672,7 +671,7 @@ impl PieceSpec for MultiSpec {
 
   #[throws(SpecError)]
   fn load(&self, i: usize, _: &mut GPiece, ig: &Instance, depth:SpecDepth)
-          -> PieceSpecLoaded
+          -> SpecLoaded
   {
     let item = self.items.get(i).ok_or_else(
       || SpE::InternalError(format!("item {:?} from {:?}", i, &self))