I want to create struct or trait(that can be implemented for both postgres::Row and clickhouse;:types::Row), but can't do that because of every of Row's get methods have own bounds - FromSql + Row/ColumnIdx. Is it possible to create something like this?
// cli is postgres or clickhouse client wrapper with stored connection in it
fn execute(cli: Box<dyn CommonClient>) -> Vec<Box<dyn CommonRow>> {
cli.query("select user_id from user")
}
A trait solution might be possible but feels like it'd be pretty tricky. You can create a generic trait and have separate bounds on the impls, something like:
trait Generic<T> {}
struct S {}
impl<T: std::fmt::Debug> Generic<T> for S {}
Maybe something like that would work? I'm not sure, hopefully someone more experienced with more complex traits can chime in.
Thank you very much for reply! Enums looks really better than structs in this case. Tried trait with generic types and found a problem that original generic types as for methods, this way i'm having to specify just one type in Client
It becomes impossible to:
let a: i64 = row.get("id");
let b: &str = row.get("username");