title: Iterate over byte vector and save pointers to strings
body: <p>I have a <code>Vec&lt;u8&gt;</code> which contains UTF-8 strings that are separated by <code>'\0' as u8</code>. Fixed length binary packed data is placed after each string, like this:</p>
  
  <p><code>b"abc\0" 10_bytes_of_data b"ufhd\0" 10_bytes_data</code>,</p>
  
  <p>I want to parse such a <code>Vec&lt;u8&gt;</code> and fill a <code>Vec&lt;&amp;str&gt;</code>. To simplify things I replace <code>10_bytes_of_data</code> with <code>0_bytes_of_data</code>:</p>
  
  <pre><code>let cnt = b"abc\0efg\0";
  let mut cnt_vec = Vec::&lt;u8&gt;::new();
  for ch in cnt {
      cnt_vec.push(*ch);
  }
  let mut str_start_it = cnt_vec.iter();
  let mut strings = Vec::&lt;&amp;str&gt;::new();
  let mut cur_it = cnt_vec.iter();
  let mut counter: usize = 0;
  loop {
      match cur_it.next() {
          Some(ch) =&gt; {
              if *ch == 0u8 {
                  {
                      let slice = str_start_it.as_slice();
                      let s = std::str::from_utf8(&amp;slice[0..counter]).unwrap();
                      strings.push(s);
                  }
                  str_start_it = cur_it.clone();
                  counter = 0;
              } else {
                  counter += 1;
              }
          }
          None =&gt; {
              break;
          }
      }
  }
  
  for s in strings {
      println!("s {}", s);
  }
  </code></pre>
  
  <p>and I have several questions:</p>
  
  <ol>
  <li><p>Is there any simpler way to convert <code>cnt</code> to <code>cnt_vec</code>?</p></li>
  <li><p>Is it possible to write the main algorithm in fewer lines of code? In the real world I have 10 bytes between strings; I plan to use <code>Iterator::nth</code>.</p></li>
  <li><p>Is there any unnecessary heap allocation in my code? I want to have heap allocations only in <code>cnt_vec</code> and <code>strings</code>, maybe some lines except <code>push</code> allocate memory on the heap? </p></li>
  </ol>