Macro row

Source
macro_rules! row {
    () => { ... };
    ( $i:ident, $($tail:tt)* ) => { ... };
    ( $i:ident ) => { ... };
    ( $k:ident: $v:expr ) => { ... };
    ( $k:ident: $v:expr, $($tail:tt)* ) => { ... };
    ( $k:expr => $v:expr ) => { ... };
    ( $k:expr => $v:expr, $($tail:tt)* ) => { ... };
}
Expand description

This macro is a convenient way to pass row into a block.

      let mut block = Block::new();
      block.push(row!{customer_id: 1, amount: 2, account_name: "foo"})?;
      block.push(row!{customer_id: 4, amount: 4, account_name: "bar"})?;
      block.push(row!{customer_id: 5, amount: 5, account_name: "baz"})?;

If a column name has special characters, you can use the alternative syntax with => to pass an expression as column name:

      let mut block = Block::new();
      block.push(row!{"customer.id" => 1, amount: 2, "account.name" => "foo"})?;
      block.push(row!{"customer.id" => 4, amount: 4, "account.name" => "bar"})?;
      block.push(row!{"customer.id" => 5, amount: 5, "account.name" => "baz"})?;

You can also use Vec<(String, Value)> to construct a row and insert it into a block:

      let mut block = Block::new();
      for i in 1..10 {
          let mut row = Vec::new();
          for j in 1..10 {
              row.push((format!("#{}", j), Value::from(i * j)));
          }
          block.push(row)?;
      }
      assert_eq!(block.row_count(), 9);