Can't use sqlx Executor as a trait object

108 views Asked by At

I need to use the Executor type as a trait object but I get the following error:

the trait `Executor` cannot be made into an object.
the trait cannot be made into an object because it requires `Self: Sized`

If we look into the trait definition, we can see how it actually implements Sized:

pub trait Executor<'c>: Send + Debug + Sized {
    type Database: Database;
...
}

I basically want to do something like the following:

struct CustomExecutor<'c> {
    inner: Arc<dyn Executor<'c, Database = Postgres>>,
}

I would expect this to work completely fine, can someone tell me what I'm doing wrong?

0

There are 0 answers