Hello! I am new to Rust and struggling with the compiler. I need to tell it that my function is generic over any tuple as long as each element satisfies the FromSql
trait but don't know how to do that. I am trying to make a function to factor out these two similar pieces of code:
// somewhere above: extern crate oracle;
conn.query_as::<(String,)>("select A from ...", &[]);
...
conn.query_as::<(String,String,String)>("select X,Y,Z from ...", &[])
I have tried this:
fn sql_to_s3<T: FromSql>(sql: &str) -> Result<(), Box<dyn Error>> {
// ...
let rows = conn.query_as::<T>(sql, &[])?;
But this is not really what I need, what I need is to say something like "T
is a tuple whose each element is FromSql
". Is it possible? How?
Thank you!!!
Background
The signature of the query_as
I need to call is
pub fn query_as<T: RowValue>(...
and the docs of oracle::RowValue
read:
The trait was added to fetch column values as a tuple. The oracle crate provides implementations for a type implementing FromSql and tuples of types implementing FromSql. The number of elements in a tuple should be 1 through 50.
There is already impl FromSql for String
. So I have everything necessary, and I just need to persuade the compiler