[−][src]Type Definition postgres_query::Parameter
type Parameter<'a> = &'a (dyn ToSql + Sync);
A shorthand for types that can be treated as SQL parameters.
A common use case for this type alias is when using dynamic bindings and you have to please the type checker:
let mut bindings = Vec::new(); // Without the `as Parameter` the compiler assumes the type to be `&i32`. bindings.push(("age", &32 as Parameter)); // Which would cause problems when adding something that is not an integer. bindings.push(("name", &"John" as Parameter)); let query = query_dyn!( "SELECT * FROM people WHERE age > $age AND name = $name", ..bindings )?;
Alternatively we could just set the type on the container explicitly:
let mut bindings: Vec<(&str, Parameter)> = Vec::new();