Hello,
I am trying to solve a rusqlite
issue.
Currently, rusqlite
uses params: &[&ToSql]
(for example, execute).
Like rust-postgres
which has the same issue and a solution.
The solution works fine except when there is no parameter:
You can't use:
db.execute("INSERT INTO foo DEFAULT VALUES", &[]);
anymore, you have to specify the type:
db.prepare("INSERT INTO foo DEFAULT VALUES", &[] as &[&ToSql]);
Do you have any suggestion ?
Here is an example that illustrates the problem with no dependency on rusqlite
:
fn collect_as_strings<T>(collection: T) -> Vec<String>
where T: IntoIterator,
T::Item : std::fmt::Debug,
{
collection
.into_iter()
.map(|item| format!("{:?}", item))
.collect()
}
fn main() {
//let data = vec![1, 2];
let data = vec![];
let strings = collect_as_strings(data);
println!("{:?}", strings)
}
Errors:
Compiling playground v0.0.1 (file:///playground)
error[E0282]: type annotations needed
--> src/main.rs:13:16
|
13 | let data = vec![];
| ---- ^^^^^^ cannot infer type for `T`
| |
| consider giving `data` a type
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
Thanks.