I am trying to build a parser combinator library in rust
I am trying to build a parser combinator library in rust
https://doc.rust-lang.org/std/string/struct.String.html#meth...
The problems you are likely running into are higher level mutability issues. The above linked function requires &mut self, which means you need a mutable string. The above linked documentation has an example of using the `mut` keyword to declare a mutable string that you can replace_range on.
Here’s the str method: https://doc.rust-lang.org/std/primitive.str.html#method.as_b...
If you want an string that is mutable, can be extended, etc. You want to use String, and that has plenty of methods for mutation.
Remember, Rust strings are all utf8, and part of the safety contract is that they’re always valid.
Note that Strings are stored as utf8, so a substring with the same number of characters can still result in a different number of bytes and thus require memmoves.