title: How to convert u8 to &[u8] in Rust?
body: <p>I am new and lost in Rust a bit.</p>
  
  <p>I would like to add keys and values to a data store that has a put function that takes two byte string literals:</p>
  
  <pre><code>batch.put(b"foxi", b"maxi");
  </code></pre>
  
  <p>I generate a bunch of these k-v pairs:</p>
  
  <pre><code>for _ in 1..1000000 {
      let mut ivec = Vec::new();
      let s1: u8 = rng.gen();
      let s2: u8 = rng.gen();
      ivec.push(s1);
      ivec.push(s2);
      debug!("Adding key: {} and value {}", s1, s2);
      vec.push(ivec);
  }
  let _ = database::write(db, vec);
  </code></pre>
  
  <p>I have a fn that tries to add them:</p>
  
  <pre><code>pub fn write(db: DB, vec: Vec&lt;Vec&lt;u8&gt;&gt;) {
      let batch = WriteBatch::new();
      for v in vec {
          batch.put(v[0], v[1]);
      }
      db.write(&amp;batch).unwrap();
  }
  </code></pre>
  
  <p>When I try to compile this I get:</p>
  
  <pre><code>error[E0308]: mismatched types
    --&gt; src/database.rs:17:19
     |
  17 |         batch.put(v[0], v[1]);
     |                   ^^^^ expected &amp;[u8], found u8
     |
     = note: expected type `&amp;[u8]`
                found type `u8`
  
  error[E0308]: mismatched types
    --&gt; src/database.rs:17:25
     |
  17 |         batch.put(v[0], v[1]);
     |                         ^^^^ expected &amp;[u8], found u8
     |
     = note: expected type `&amp;[u8]`
                found type `u8`
  </code></pre>
  
  <p>I was ping-ponging with the borrow checker for a while now but I could not get it working. What is the best way to have byte literal strings from u8s?</p>