4 ms·
Out of curiosity, what did you parse? Since in I imagine copying things is quite useful sometimes when generating an AST. On top of that, I think sometimes you
by spoiler 5y ago
Out of curiosity, what did you parse? Since in I imagine copying things is quite useful sometimes when generating an AST. On top of that, I think sometimes you can't avoiding copying (imagine a string with special backslash sequences like \x20, you probably copy parts of the string that don't need special interpolation)
- juancampa 5y agoThat's right. At that point I learned about std::borrow::Cow (copy-on-write) and it worked pretty nicely. The unescaping is done lazily (on access) so it's indeed zero-copy unless strictly necessary. The parser was for a tiny language we use to express references within graphs over at membrane.io. similar to URLs but typed and not ambiguous. It's simple enough. Perhaps writing a URL parser would be good for learning.