Need: I am trying to implement sql:: frowrow, but an error is reported when defining it
in fn new(pool: Arc) _from_row parameter error
pub struct Table<'c, T>
where
T: FromRow<'c, MySqlRow>,
{
pub pool: Arc<MySqlPool>,
_from_row: fn(&MySqlRow) -> Result<T, sqlx::Error>,
phantom: PhantomData<&'c T>,
}
impl<'c, T> Table<'c, T>
where
T: FromRow<'c, MySqlRow>,
{
fn new(pool: Arc<MySqlPool>) -> Self {
Table {
pool,
phantom: PhantomData,
_from_row: T::from_row,
//implementation of `sqlx::FromRow` is not general enough
//doesn't satisfy where-clause
//note: ...`T` must implement `sqlx::FromRow<'0, sqlx::mysql::MySqlRow>`, for some specific lifetime `'0`...
//note: ...but it actually implements `sqlx::FromRow<'c, sqlx::mysql::MySqlRow>`
}
}
}
pub struct Database<'c> {
pub groups: Arc<Table<'c, Group>>,
}
impl from_row method in Group model
use serde::{Deserialize, Serialize};
use sqlx::mysql::MySqlRow;
use sqlx::{FromRow, Row};
#[derive(Serialize, Deserialize, PartialEq, Clone)]
pub struct Group {
pub id: u64,
pub name: String,
}
impl<'c> FromRow<'c, MySqlRow> for Group {
fn from_row(row: &'c MySqlRow) -> Result<Self, sqlx::Error> {
Ok(Group {
id: row.get(0),
name: row.get(1),
})
}
}
Error:
implementation of `sqlx::FromRow` is not general enough
doesn't satisfy where-clause
note: ...`T` must implement `sqlx::FromRow<'0, sqlx::mysql::MySqlRow>`, for some specific lifetime `'0`...
note: ...but it actually implements `sqlx::FromRow<'c, sqlx::mysql::MySqlRow>`
Question: I have implements the method sqlx::FromRow<'c, sqlx::mysql::MySqlRow> in the 'Group' model
Sqlx dependency:
sqlx = { version = "0.5.11", features = ["chrono","runtime-actix-rustls","mysql"] }