title: How do I load SQLX records to Vec of structs in Rust
body: <p>I have a table named instruments with the  following fields:</p>
  
  <ul>
  <li><code>id</code>,</li>
  <li><code>instrument_token</code> (integer)</li>
  <li><code>tradingsymbol</code> (nullable string field) </li>
  </ul>
  
  <p>I have defined a Rust struct as below</p>
  
  <pre><code>pub struct Instrument {
      pub id: i64,
      pub instrument_token: i32,
      pub tradingsymbol: Option&lt;String&gt;,
  }
  </code></pre>
  
  <p>I query and create a <code>Vec&lt;Instrument&gt;</code> inside a function as follows using SQLX</p>
  
  <pre class="lang-rust prettyprint-override"><code>     let records = sqlx::query!(r"select * from instruments").fetch_all(&amp;app_context.db_connection).await?;
  
  
          let mut all_instruments: Vec&lt;Instrument&gt; = Vec::new();
          for rec in records {
              all_instruments.push(Instrument {
                  id: rec.id,
                  instrument_token: rec.instrument_token,
                  tradingsymbol: rec.tradingsymbol,
              });
          }
  
  </code></pre>
  
  <p>Here <code>&amp;app_context.db_connection</code> is <code>&amp;pool</code> instance.</p>
  
  <p>Is this there a better way to load records to a struct using SQLX.
  If yes how?</p>