chiark / gitweb /
Use dyn_upcast for OutlineTrait (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 8 Mar 2021 23:31:38 +0000 (23:31 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 10 Mar 2021 21:52:29 +0000 (21:52 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/hand.rs
src/imports.rs
src/pieces.rs
src/prelude.rs
src/shapelib.rs
src/spec.rs

index ea6ca7e939cf525e15fe0465b62796fe652baf4e..33294c1d1b0f8334c60109c575d24c3bc1f23aa6 100644 (file)
@@ -108,6 +108,7 @@ pub trait PieceXData: Downcast + Debug + Send + 'static {
 impl_downcast!(PieceXData);
 
 #[enum_dispatch]
+#[dyn_upcast]
 pub trait OutlineTrait: Send + Debug {
   fn outline_path(&self, scale: f64) -> Result<Html, IE>;
   fn surround_path(&self) -> Result<Html, IE> {
index 175d10d333232badbae8dadc589c80067c0ef038..dc9699fc8a754c8338701477ef00bcd5bd5135b1 100644 (file)
@@ -35,6 +35,7 @@ impl HandState {
 #[typetag::serde(name="Hand")]
 impl PieceXData for HandState { }
 
+#[dyn_upcast]
 impl OutlineTrait for Hand {
   delegate!{
     to self.shape {
index 797824db0522aca485efd68d4a203391cb99ab9c..af48fc21d594e4943896b901a192425ed853810a 100644 (file)
@@ -7,6 +7,7 @@ pub use otter_base::imports::*;
 
 pub use anyhow;
 pub use boolinator;
+pub use cast_trait_object;
 pub use chrono;
 pub use chrono_tz;
 pub use delegate;
index 9b7a05be53fbdac677d1ef58a82680579f401758..6962b3f4d046a298858e45368bb8e03f8023cbfe 100644 (file)
@@ -111,7 +111,8 @@ pub fn svg_rectangle_path(PosC([x,y]): PosC<f64>) -> Html {
                -x*0.5, -y*0.5, x, y, -x))
 }
 
-impl<Desc, Outl> OutlineTrait for GenericSimpleShape<Desc, Outl>
+#[dyn_upcast]
+impl<Desc, Outl:'static> OutlineTrait for GenericSimpleShape<Desc, Outl>
     where Desc: Debug + Send + Sync + 'static,
           Outl: OutlineTrait,
 {
@@ -145,7 +146,7 @@ impl PieceTrait for SimpleShape {
   fn itemname(&self) -> &str { self.itemname() }
 }
 
-impl<Desc, Outl> GenericSimpleShape<Desc, Outl>
+impl<Desc, Outl:'static> GenericSimpleShape<Desc, Outl>
     where Desc: Debug + Send + Sync + 'static,
           Outl: OutlineTrait,
 {
index 05636ebece086ae9a8ebf43494b398446f86e998..4b34c4baf14d6feb407ae23e3675e3a440db58a0 100644 (file)
@@ -52,6 +52,7 @@ pub use std::time::{self, Duration, Instant};
 pub use anyhow::{anyhow, ensure, Context};
 pub use arrayvec::ArrayVec;
 pub use boolinator::Boolinator as _;
+pub use cast_trait_object::{dyn_upcast, DynCastExt};
 pub use delegate::delegate;
 pub use derive_more::*;
 pub use downcast_rs::{impl_downcast, Downcast};
index c1b4a8b5333a2beccfb3f76491097c9ba9434909..60dee0ed92829b812ba86dc6480a8cf8bee0542b 100644 (file)
@@ -142,6 +142,7 @@ impl ItemEnquiryData {
   }
 }
 
+#[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>;
@@ -490,6 +491,7 @@ pub fn load(libs: &Vec<Config1>) {
 #[derive(Clone,Copy,Debug,Serialize,Deserialize)]
 pub struct Circle { pub diam: f64 }
 
+#[dyn_upcast]
 impl OutlineTrait for Circle {
   #[throws(IE)]
   fn outline_path(&self, scale: f64) -> Html {
@@ -532,6 +534,7 @@ impl CircleDefn {
 #[derive(Clone,Copy,Debug,Serialize,Deserialize)]
 pub struct Rectangle { pub xy: PosC<f64> }
 
+#[dyn_upcast]
 impl OutlineTrait for Rectangle {
   #[throws(IE)]
   fn outline_path(&self, scale: f64) -> Html {
index 06af4565850402581646b5e345ba960d6be9b7be..bb83d99b9a9a3113f89041669fc90ec8a496a089 100644 (file)
@@ -199,6 +199,7 @@ mod outline {
   use super::*;
   use crate::prelude::*;
   use crate::shapelib::{Circle, Rectangle};
+  #[dyn_upcast(OutlineTrait)]
   #[enum_dispatch(OutlineTrait)]
   #[derive(Clone,Debug,Serialize,Deserialize)]
   #[serde(tag="type")]