My Favorite Rust Function Signature
Tokenizers usually need to retain some information about where each token came from, like the range in the source.<p>In C++ I might do it like this:<p><pre><code>    struct token {
        string::iterator start;
        string::iterator end;
    };
</code></pre>
and then the range in the original source can be recovered via:<p><pre><code>    size_t offset = tok.start - src.begin();
</code></pre>
What is the preferred way to do this in Rust? Is there something better than using indexes?<p>Rust doesn't appear to have a way to say "give me the location of this &str in that &str" (even though it seems like it would be safe).