title: What is the equivalent of a safe memset for slices?
body: <p>In many cases, I need to clear areas of buffers or set a slice to certain value. What is the native recommended way of doing this?</p>
  
  <p>This is invalid Rust, but I would like to do something similar to this:</p>
  
  <pre><code>let mut some_buffer = vec![0u8; 100];
  buffer[10..20].set(0xFF)
  </code></pre>
  
  <p>I could use a for loop but I have the feeling I am missing something given that I am new to Rust.</p>
  
  <p>In C++, I would do something like:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>std::array&lt;int,6&gt; foobar;
  foobar.fill(5);
  </code></pre>
  
  <p>In Python, it would be similar:</p>
  
  <pre class="lang-py prettyprint-override"><code>tmp = np.zeros(10)
  tmp[3:6]=2
  </code></pre>