Re:UTF-8 String Indexing Strategies
by the_mitsuhiko on Thursday May 30, 2019 @06:18AM
(#20049786)
From my personal experience I think Rust's string system is hard to beat at the moment. It's pretty darn good from a usability point of view and it also found a nice solution to work with UCS2 windows APIs by providing a OsStr type.
[ Parent
| on HN ]
Re:UTF-8 String Indexing Strategies
by chrismorgan on Thursday May 30, 2019 @07:01AM
(#20049966)
I’m glad that Rust strings aren’t indexable by integer, but I think that making them indexable by range (of UTF-8 code unit offsets) was an error. `foo[0..10]` should have been `foo.slice(0..10)` or similar instead.
Re:UTF-8 String Indexing Strategies
by the_mitsuhiko on Thursday May 30, 2019 @07:10AM
(#20050020)
It’s a bit of a footgun indeed but it’s quite handy in combination with the char index iterator.
Re:UTF-8 String Indexing Strategies
by chrismorgan on Thursday May 30, 2019 @09:40AM
(#20050999)
Sure, you do want to be able to index by code unit range, but it shouldn’t have been with the Index trait.
There's no reason this couldn't be added now, though, right?
Re:UTF-8 String Indexing Strategies
by richardwhiuk on Thursday May 30, 2019 @06:33AM
(#20049834)
The only annoyance is the occasional unwrap, when something is provably impossible, but the type system can't detect it.