Re:Thoughts on Rust, a few thousand lines in
by da_chicken on Wednesday January 09, 2019 @09:03PM
(#18870919)
Who cares if it's O(1) if it causes a panic? What good is high performance if it doesn't complete or isn't safe?
At the very least, shouldn't there be an O(n) method to do character-wise slicing?
Re:Thoughts on Rust, a few thousand lines in
by steveklabnik on Wednesday January 09, 2019 @09:09PM
(#18870946)
panics are safe. You expect the “I don’t have a bug” case to be fast.
You can, but it depends on what you mean by “character”, as that’s not a concept in Unicode. Every kind of thing you could mean has a method, specific to it, since they’re different things.
(char in Rust is a Unicode scalar value, and you can collect into a Vec<char> and then slice it, as an example of one of those things. And that’s still O(1) at the cost of using up to four times the memory.)
> If a string is an array of characters
It is not, it is an array (technically vector) of bytes.