rust/library
Mark Lodato 9cf35a6c06 Rework String UTF-8 Documentation
**This Commit**
Adds some clarity around indexing into Strings and the constraints
driving various decisions there.

**Why?**
The [`String` documentation][0] mentions how `String`s can't be indexed
but `Range` has an implementation for `SliceIndex<str>`. This can be
confusing. There are also several statements to explain the lack of
`String` indexing:

- the inability to index into a `String` is an implication of UTF-8
  encoding
- indexing into a `String` could not be constant-time with UTF-8
  encoding
- indexing into a `String` does not have an obvious return type

This last statement made sense but the first two seemed contradictory to
the documentation around [`SliceIndex<str>`][1] which mention:

- one can index into a `String` with a `Range` (also called substring
  slicing but it uses the same syntax and the method name is `index`)
- `Range` indexing into a `String` is constant-time

To resolve this seeming contradiction the documentation is reworked to
more clearly explain what factors drive the decision to disallow
indexing into a `String` with a single number.

[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
2022-04-09 09:27:32 -04:00
..
alloc Rework String UTF-8 Documentation 2022-04-09 09:27:32 -04:00
backtrace@b02ed04a7e Updated backtrace submodule 2021-11-02 12:31:34 +01:00
core Rollup merge of #95787 - yaahc:panic-doc-update-v2, r=dtolnay 2022-04-09 05:58:44 +02:00
panic_abort Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
panic_unwind library/panic_unwind: Define UNWIND_DATA_REG for m68k 2022-02-12 20:19:06 +00:00
portable-simd Sync portable-simd to rust-lang/portable-simd@72df4c4505 2022-03-12 16:09:37 -08:00
proc_macro trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
profiler_builtins Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rtstartup
rustc-std-workspace-alloc Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-core Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-std Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
std Add ThinBox type for 1 stack pointer sized heap allocated trait objects 2022-04-08 09:00:16 -07:00
stdarch@bcbe010614 Update stdarch submodule 2022-03-02 20:06:46 +01:00
test Auto merge of #95678 - pietroalbini:pa-1.62.0-bootstrap, r=Mark-Simulacrum 2022-04-07 07:34:04 +00:00
unwind Auto merge of #95678 - pietroalbini:pa-1.62.0-bootstrap, r=Mark-Simulacrum 2022-04-07 07:34:04 +00:00