Reputation: 6246
I think it would be logical (str
is after all a vector of u8
) and useful to be able to use the functions defined in ImmutableVector
. Does anyone have an explanation?
Upvotes: 2
Views: 88
Reputation: 6246
I am going to paste here one answer I got in the subreddit of Rust, by erickt, in the hope that it can be useful to someone else:
The reason we do this is because str is a Unicode string, and the fact that the underlying storage is an implementation detail. There are many ways at iterating over the things in a string. First , you could go over the bytes, which is what you would get with ImmutableVector. However those bytes don't correspond to characters, since strs are UTF8, multiple bytes may make up one character. But then there are even more choices. Some languages can perceive two characters being combined into one, and so on. Iternationalization is complicated. I would suggest checking out this link that goes into way more detail about this topic.
Upvotes: 4