我在应用程序中有一个通用特性,可以在不同的存储空间中转换结果。现在,我想添加对SQLx的支持。我想保持它通用于所有sqlx引擎。
I64的简化示例:
// My trait
pub trait TryConvert {
fn try_i64(&self) -> i64;
}第一步尝试:
// Gives error
// the trait `sqlx::Decode<'_, DB>` is not implemented for `i64`
impl<DB, V> TryConvert for V
where
DB: Database,
V: Value<Database = DB>,
{
fn try_i64(&self) -> i64 {
self.try_decode_unchecked().unwrap()
}
}现在使用Decode for i64:
// Gives error:
// expected `sqlx::Decode<'_, DB>` found `sqlx::Decode<'a, DB>`
impl<'a, DB, V> TryConvert for V
where
DB: Database,
V: Value<Database = DB>,
i64: Decode<'a, DB>,
{
fn try_i64(&self) -> i64 {
self.try_decode_unchecked().unwrap()
}
}但是,所有这些都使用具体的DB类型:
impl<V> TryConvert for V
where
V: Value<Database = Sqlite>,
{
fn try_i64(&self) -> i64 {
self.try_decode_unchecked().unwrap()
}
}对于任何sqlx引擎,是否可以保留TryConvert的泛型?
https://stackoverflow.com/questions/69236707
复制相似问题