I have this Rusqlite code:
use rusqlite::types::ToSql;
// ... normal Rusqlite initialisation code ...
let mut statement = tx.prepare("INSERT INTO table VALUES (?1, ?2)")?;
let params: &[&dyn ToSql] = &[
&0u32,
&"hello",
];
statement.execute(params)?;
The ?1
parameter is an INTEGER
and the ?2
parameter is TEXT
. This compiles, however if I move the params
into the function call it does not compile:
statement.execute(&[
&0u32,
&"hello",
])?;
This gives the following error for &hello
.
mismatched types
expected type `&u32`
found reference `&&'static str`
It seems like it infers the type for the array literal based on the type of the first element. What is the syntax for explicitly setting the type of the array?