diff options
| author | Mark Lodato <mlodato517@gmail.com> | 2022-03-09 21:43:04 -0500 |
|---|---|---|
| committer | Mark Lodato <mlodato517@gmail.com> | 2022-04-09 09:27:32 -0400 |
| commit | 9cf35a6c06da5699efcf417eecaa2d33b3a0d13b (patch) | |
| tree | ff237e97f8894c91a5ff25e6fb50de6a70873fdd /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | 399dd8049d4b27329350937e3e17077205bdc0bf (diff) | |
| download | rust-9cf35a6c06da5699efcf417eecaa2d33b3a0d13b.tar.gz rust-9cf35a6c06da5699efcf417eecaa2d33b3a0d13b.zip | |
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
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
