Closed lquerel closed 2 years ago
I don't believe this has anything to do with async_trait.
struct Error;
struct Configurator;
struct Msg;
trait EffectHandler<Msg> {}
trait Receiver<Msg: 'static + Clone + Send>: Send {
fn is_singleton(&self) -> bool;
fn init(&mut self, configurator: Configurator) -> Result<(), Error>;
fn run(&mut self, effect_handler: impl EffectHandler<Msg>) -> Result<(), Error>;
fn stop(&mut self) {}
}
fn create() -> Result<Box<dyn Receiver<Msg> + Send + Sync>, Error> {unimplemented!()}
error[E0038]: the trait `Receiver` cannot be made into an object
--> src/lib.rs:13:16
|
13 | fn create() -> Result<Box<dyn Receiver<Msg> + Send + Sync>, Error> {unimplemented!()}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Receiver` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> src/lib.rs:9:8
|
6 | trait Receiver<Msg: 'static + Clone + Send>: Send {
| -------- this trait cannot be made into an object...
...
9 | fn run(&mut self, effect_handler: impl EffectHandler<Msg>) -> Result<(), Error>;
| ^^^ ...because method `run` has generic type parameters
= help: consider moving `run` to another trait
Indeed. My bad :)
I don't understand why this code doesn't compile.
The error returned by the compiler is:
Note that I'd like to keep
impl
theeffect_handler
parameter in therun
method.Thanks