macro_rules! named_params {
    () => { ... };
    ($($param_name:literal: $param_val:expr),+ $(,)?) => { ... };
}
Expand description

A macro making it more convenient to pass lists of named parameters as a &[(&str, &dyn ToSql)].

Example


struct Person {
    name: String,
    age_in_years: u8,
    data: Option<Vec<u8>>,
}

fn add_person(conn: &Connection, person: &Person) -> Result<()> {
    conn.execute(
        "INSERT INTO person (name, age_in_years, data)
         VALUES (:name, :age, :data)",
        named_params! {
            ":name": person.name,
            ":age": person.age_in_years,
            ":data": person.data,
        },
    )?;
    Ok(())
}