Object polymorphism/Moving Box<dyn T>

error[E0161]: cannot move a value of type dyn Converter + std::marker::Send: the size of dyn Converter + std::marker::Send cannot be statically determined
  --> src/main.rs:64:9
   |
64 |         converter.run().await;
   |         ^^^^^^^^^

I guess it is not possible to take ownership with #[async_trait] if it is also in a box

How to fix it?

In this case I would probably just replace the trait with an enum. You simply can't call by-value methods on trait objects.

How about moving run out of the trait altogether? This works for me.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.