title: get byte offset after first char of str in rust
body: <p>In rust, I want to get the byte offset immediately after of the first character of a <code>str</code>.</p>
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=d0c7e9626492ee33752110d10efc6d4e" rel="nofollow noreferrer">Rust Playground</a></p>
  <pre class="lang-rust prettyprint-override"><code>fn main() {
      let s: &amp;str = &quot;⚀⚁&quot;;
      // char is 4 bytes, right??? (not always when in a str)
      let offset: usize = 4;
      let s1: &amp;str = &amp;s[offset..];
      eprintln!(&quot;s1 {:?}&quot;, s1);
  }
  </code></pre>
  <p>The program expectedly crashes with:</p>
  <pre><code>thread 'main' panicked at 'byte index 4 is not a char boundary; it is inside '⚁' (bytes 3..6) of `⚀⚁`'
  </code></pre>
  <p><strong>How can find the byte offset for the second char <code>'⚁'</code> ?</strong></p>
  <p>Bonus if this can be done safely and without <code>std</code>.</p>
  <br/>
  <hr />
  <p>Related:</p>
  <ul>
  <li><a href="https://stackoverflow.com/q/38268529/471376">How to get the byte offset between <code>&amp;str</code></a></li>
  <li><a href="https://stackoverflow.com/q/50781561/471376">How to find the starting offset of a string slice of another string?</a></li>
  </ul>