From: Ian Jackson Date: Sat, 14 May 2022 22:17:20 +0000 (+0100) Subject: impl OutlineTrait via ambassador for many types X-Git-Tag: otter-1.1.0~157 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0f1b8d4460934a461ec33265a351f921ac688aa9;p=otter.git impl OutlineTrait via ambassador for many types We're going to add a method... Signed-off-by: Ian Jackson --- diff --git a/src/currency.rs b/src/currency.rs index f5403f5d..ba91acb2 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -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; - fn thresh_dragraise(&self) -> Result, IE>; - fn bbox_approx(&self) -> Result; - } - } +impl_via_ambassador!{ + #[dyn_upcast] + impl OutlineTrait for Banknote { image } } #[dyn_upcast] diff --git a/src/deck.rs b/src/deck.rs index 10fb6d97..ab460342 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -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; - fn thresh_dragraise(&self) -> Result,IE>; - fn bbox_approx(&self) -> Result; - } - } +impl_via_ambassador!{ + #[dyn_upcast] + impl OutlineTrait for Deck { shape } } #[typetag::serde(name="PickupDeck")] diff --git a/src/hand.rs b/src/hand.rs index 960e38af..ed4a1e8b 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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; - fn thresh_dragraise(&self) -> Result,IE>; - fn bbox_approx(&self) -> Result; - } - } +impl_via_ambassador!{ + #[dyn_upcast] + impl OutlineTrait for Hand { shape } } impl piece_specs::OwnedCommon { diff --git a/src/pieces.rs b/src/pieces.rs index 9c3c2683..bb38f948 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -5,6 +5,7 @@ // pieces use crate::prelude::*; +use crate::*; // to get ambassador_impls, macro resolution trouble use piece_specs::SimpleCommon; diff --git a/src/shapelib.rs b/src/shapelib.rs index 1f794159..4410378c 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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 SvgBaseName where T: Borrow { //==================== impls for ItemInertForOcculted ==================== -#[dyn_upcast] -impl OutlineTrait for ItemInertForOcculted { delegate! { to self.outline { - fn outline_path(&self, scale: f64) -> Result; - fn thresh_dragraise(&self) -> Result, IE>; - fn bbox_approx(&self) -> Result; -}}} +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; - fn thresh_dragraise(&self) -> Result, IE>; - fn bbox_approx(&self) -> Result; -}}} +impl_via_ambassador!{ + #[dyn_upcast] + impl OutlineTrait for Item { outline } +} impl Item { #[throws(IE)]