Box<MyTrait>
isn't Send
/Sync
, because it could be any implementation, not just the ones that meet that requirement. If you want to constraint the trait object to also be Send
/Sync
, add it to the type:
trait UserRepository {}
struct PostgresUserRepository {
database: Box<Database + Send + Sync>,
}
impl UserRepository for PostgresUserRepository {}
See Sending trait objects between threads - #3 by Gankra for a bit more info.