Closed cwhakes closed 5 years ago
I think you would need Send as a supertrait in order to do the deserialization.
#[typetag::serde(tag = "type")]
trait MyTrait: Send {}
Otherwise, if you allow implementations of MyTrait that do not implement Send, the trait system does not have a way to weed out those implementations when deserializing into Box\<MyTrait + Send>.
I had tried to add Send
as a supertrait before, but that didn't work. Including the Send
as a supertrait and modifying Data
to not need it worked.
#[derive(Serialize, Deserialize)]
struct Data ( Arc<Mutex<Box<dyn MyTrait>>> );
Both Box<dyn MyTrait>
and Box<dyn MyTrait + Send>
should work equivalently as of typetag 0.1.2 if you have Send as a supertrait -- but the second is redundant anyway when we already know all implementations of MyTrait are Send from the supertrait bound. Glad you got it working!
I am trying to serialize/deserialize a global trait object, but it appears that the Serialize/Deserialize implementations aren't being implemented for marker traits.
Example:
This generates the error(s):