-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
-
The codepoint iterator
charsis not mentioned in http://doc.rust-lang.org/master/guide-strings.html#indexing-strings -
The use of
Strin http://doc.rust-lang.org/master/guide-strings.html#generic-functions is not particularly idiomatic; sinceTis at the 'top level' taking a&strdirectly is fine; being generic overStris better when it may be expensive for the user to get to a&str, e.g. if the string data is inside somethingfn foo(x: &[&str]) fn bar<T: Str>(x: &[T])If the user has
&[String]and wants to callfoo, they're forced to allocate storage to store the.as_slice's of each element, which can be arbitrarily expensive (they may have a lot ofStrings);bargets around this since it can be called with&[String]or&[&str].(FWIW, this is actually still true for functions taking iterators, even though one can sometimes
.map(|s| s.as_slice())to get aIterator<&str>. If you have aIterator<String>, there's no way to convert that into aIterator<&str>without collecting into a temporary data structure.)