I'm trying to loosely implement the repository pattern for an application I'm building, however I seem to have hit on some kind of recursive type definition by accident.
On the following code:
use diesel::{pg::Pg, Insertable, Queryable, QueryDsl, PgConnection, Identifiable, Table};
use std::marker::PhantomData;
use anyhow::anyhow;
pub struct Repository<Entity, SqlType, Tab> {
_entity_phantom: PhantomData<Entity>,
_type_phantom: PhantomData<SqlType>,
table: Tab,
}
impl <Entity, SqlType, Tab> Repository<Entity, SqlType, Tab>
where
Entity: Queryable<SqlType, Pg> + Insertable<Tab> + Identifiable,
Tab: Table
{
fn find_by_id(&self, id: i64, conn: &PgConnection) -> anyhow::Result<Entity> {
match self.table.find(id).first::<Entity>(conn) {
Ok(entity) => Ok(entity),
Err(e) => Err(anyhow!("{}", e)),
}
}
}
I get the error:
error[E0275]: overflow evaluating the requirement `_: Sized`
--> support/src/lib.rs:18:26
|
18 | match self.table.find(id).first::<Entity>(conn) {
| ^^^^
|
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`support`)
= note: required because of the requirements on the impl of `FilterDsl<_>` for `<Tab as AsQuery>::Query`
I've tried increasing the recursion limit at the top of the crate, but to no avail. Sprinking + Sized all over the trait bounds, doesn't seem to do anything as well.
What am I missing?