1ced0b61a4
Clarify indexing into Strings **This Commit** Adds some clarity around indexing into Strings. **Why?** I was reading through the `Range` documentation and saw an implementation for `SliceIndex<str>`. I was surprised to see this and went to read the [`String`][0] documentation and, to me, it seemed to say (at least) three things: 1. you cannot index into a `String` 2. indexing into a `String` could not be constant-time 3. indexing into a `String` does not have an obvious return type I absolutely agree with the last point but the first two seemed contradictory to the documentation around [`SliceIndex<str>`][1] which mention: 1. you can do substring slicing (which is probably different than "indexing" but, because the method is called `index` and I associate anything with square brackets with "indexing" it was enough to confuse me) 2. substring slicing is constant-time (this may be algorithmic ignorance on my part but if `&s[i..i+1]` is O(1) then it seems confusing that `&s[i]` _could not possibly_ be O(1)) So I was hoping to clarify a couple things and, hopefully, in this PR review learn a little more about the nuances here that confused me in the first place. [0]: https://doc.rust-lang.org/stable/std/string/struct.String.html#utf-8 [1]: https://doc.rust-lang.org/stable/std/slice/trait.SliceIndex.html#impl-SliceIndex%3Cstr%3E |
||
---|---|---|
.. | ||
alloc | ||
backtrace@b02ed04a7e | ||
core | ||
panic_abort | ||
panic_unwind | ||
portable-simd | ||
proc_macro | ||
profiler_builtins | ||
rtstartup | ||
rustc-std-workspace-alloc | ||
rustc-std-workspace-core | ||
rustc-std-workspace-std | ||
std | ||
stdarch@bcbe010614 | ||
test | ||
unwind |