chiark / gitweb /
impl OutlineTrait via ambassador for many types
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 22:17:20 +0000 (23:17 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 22:34:03 +0000 (23:34 +0100)
We're going to add a method...

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

index f5403f5d48804c9d3f7643ae3438dd42f19959fd..ba91acb206eef53363e0644b482f5ae879f717e5 100644 (file)
@@ -14,6 +14,7 @@
 //  - can have a back face which is less manipulable (if image has 2 faces)
 
 use crate::prelude::*;
+use crate::*; // to get ambassador_impls, macro resolution trouble
 
 const QTY_FONT_SIZE: f64 = 6.;
 
@@ -79,15 +80,9 @@ impl PieceSpec for Spec {
   }
 }
 
-#[dyn_upcast]
-impl OutlineTrait for Banknote {
-  delegate!{
-    to self.image {
-      fn outline_path(&self, scale: f64) -> Result<Html, IE>;
-      fn thresh_dragraise(&self) -> Result<Option<Coord>, IE>;
-      fn bbox_approx(&self) -> Result<Rect, IE>;
-    }
-  }
+impl_via_ambassador!{
+  #[dyn_upcast]
+  impl OutlineTrait for Banknote { image }
 }
 
 #[dyn_upcast]
index 10fb6d97e68a1b504ac604cf5fa7290755bae6f7..ab4603423d2a8dd39e8b29851256ba7507a56469 100644 (file)
@@ -3,6 +3,7 @@
 // There is NO WARRANTY.
 
 use crate::prelude::*;
+use crate::*; // to get ambassador_impls, macro resolution trouble
 
 pub const CORE_DESC    : HtmlLit = Html::lit("a play/pickup deck");
 pub const DISABLED_DESC: HtmlLit = Html::lit("a play/pickup deck (disabled)");
@@ -23,15 +24,9 @@ enum State {
 }
 use State::*;
 
-#[dyn_upcast]
-impl OutlineTrait for Deck {
-  delegate!{
-    to self.shape {
-      fn outline_path(&self, scale: f64) -> Result<Html,IE>;
-      fn thresh_dragraise(&self) -> Result<Option<Coord>,IE>;
-      fn bbox_approx(&self) -> Result<Rect, IE>;
-    }
-  }
+impl_via_ambassador!{
+  #[dyn_upcast]
+  impl OutlineTrait for Deck { shape }
 }
 
 #[typetag::serde(name="PickupDeck")]
index 960e38afbe6563bfe3e879eb24b4a2a2a8afefd7..ed4a1e8ba3cf1840ba21a9cc69c5bec59156e675 100644 (file)
@@ -3,6 +3,7 @@
 // There is NO WARRANTY.
 
 use crate::prelude::*;
+use crate::*; // to get ambassador_impls, macro resolution trouble
 
 pub const UNCLAIMED_HAND_DESC: &str = "a hand repository";
 
@@ -75,15 +76,9 @@ impl PieceXData for HandState {
   fn dummy() -> Self { default() }
 }
 
-#[dyn_upcast]
-impl OutlineTrait for Hand {
-  delegate!{
-    to self.shape {
-      fn outline_path(&self, scale: f64) -> Result<Html,IE>;
-      fn thresh_dragraise(&self) -> Result<Option<Coord>,IE>;
-      fn bbox_approx(&self) -> Result<Rect, IE>;
-    }
-  }
+impl_via_ambassador!{
+  #[dyn_upcast]
+  impl OutlineTrait for Hand { shape }
 }
 
 impl piece_specs::OwnedCommon {
index 9c3c2683b6931c373f3aebe361913b415d7f2cc4..bb38f9481fcb10c2652781137b584453c6d8e3e0 100644 (file)
@@ -5,6 +5,7 @@
 // pieces
 
 use crate::prelude::*;
+use crate::*; // to get ambassador_impls, macro resolution trouble
 
 use piece_specs::SimpleCommon;
 
index 1f79415974fba6d1594b8c7df1cccfef77e40cb2..4410378c77ddbc61f4386e661bef006d53d5e3c4 100644 (file)
@@ -3,6 +3,7 @@
 // There is NO WARRANTY.
 
 use crate::prelude::*;
+use crate::*; // to get ambassador_impls, macro resolution trouble
 pub use crate::shapelib_toml::*;
 
 pub use crate::prelude::GoodItemName; // not sure why this is needed
@@ -258,12 +259,10 @@ impl<T> SvgBaseName<T> where T: Borrow<GoodItemName> {
 
 //==================== impls for ItemInertForOcculted ====================
 
-#[dyn_upcast]
-impl OutlineTrait for ItemInertForOcculted { delegate! { to self.outline {
-  fn outline_path(&self, scale: f64) -> Result<Html, IE>;
-  fn thresh_dragraise(&self) -> Result<Option<Coord>, IE>;
-  fn bbox_approx(&self) -> Result<Rect, IE>;
-}}}
+impl_via_ambassador!{
+  #[dyn_upcast]
+  impl OutlineTrait for ItemInertForOcculted { outline }
+}
 #[dyn_upcast]
 impl PieceBaseTrait for ItemInertForOcculted {
   fn nfaces(&self) -> RawFaceId { 1 }
@@ -334,12 +333,10 @@ impl Display for LibraryEnquiryData {
 
 //==================== Item ====================
 
-#[dyn_upcast]
-impl OutlineTrait for Item { delegate! { to self.outline {
-  fn outline_path(&self, scale: f64) -> Result<Html, IE>;
-  fn thresh_dragraise(&self) -> Result<Option<Coord>, IE>;
-  fn bbox_approx(&self) -> Result<Rect, IE>;
-}}}
+impl_via_ambassador!{
+  #[dyn_upcast]
+  impl OutlineTrait for Item { outline }
+}
 
 impl Item {
   #[throws(IE)]