#Can you use component as trait object?

3 messages · Page 1 of 1 (latest)

neat estuary
#

Hi, I tried to derive component to a struct that has a trait object for a field, but I got error that it needs to implement "Sync" and "Send" to be thread safe, I tried a lot of caveats around it, but I can't get it to work. My latest idea is that I will just use component as trait object. Is it possible to do?

wheat marten
#

You mean something like this?

#[derive(Component)]
struct MyComponent {
    field: Box<dyn Any + Send + Sync>,
}
#

You need to add Send + Sync as bounds for the trait object