Description
-
The codepoint iterator
chars
is not mentioned in http://doc.rust-lang.org/master/guide-strings.html#indexing-strings -
The use of
Str
in http://doc.rust-lang.org/master/guide-strings.html#generic-functions is not particularly idiomatic; sinceT
is at the 'top level' taking a&str
directly is fine; being generic overStr
is 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 ofString
s);bar
gets 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.)