Skip to content

Commit 1e2bb09

Browse files
committed
auto merge of #14435 : P1start/rust/str-docs-fix, r=sfackler
This tweaks the `std::str` docs to compensate for the recent shift from `~str` to `String`.
2 parents 5811d2b + c1fd345 commit 1e2bb09

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/libstd/str.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ Unicode string manipulation (`str` type)
1616
1717
Rust's string type is one of the core primitive types of the language. While
1818
represented by the name `str`, the name `str` is not actually a valid type in
19-
Rust. Each string must also be decorated with its ownership. This means that
20-
there is one common kind of string in Rust:
19+
Rust. Each string must also be decorated with a pointer. `String` is used
20+
for an owned string, so there is only one commonly-used `str` type in Rust:
21+
`&str`.
2122
22-
* `&str` - This is the borrowed string type. This type of string can only be
23-
created from the other kind of string. As the name "borrowed"
24-
implies, this type of string is owned elsewhere, and this string
25-
cannot be moved out of.
23+
`&str` is the borrowed string type. This type of string can only be created
24+
from other strings, unless it is a static string (see below). As the word
25+
"borrowed" implies, this type of string is owned elsewhere, and this string
26+
cannot be moved out of.
2627
27-
As an example, here's the one kind of string.
28+
As an example, here's some code that uses a string.
2829
2930
```rust
3031
fn main() {
3132
let borrowed_string = "This string is borrowed with the 'static lifetime";
3233
}
3334
```
3435
35-
From the example above, you can see that Rust has 1 different kind of string
36-
literal. The "borrowed literal" is akin to C's concept of a static string.
36+
From the example above, you can see that Rust's string literals have the
37+
`'static` lifetime. This is akin to C's concept of a static string.
3738
3839
String literals are allocated statically in the rodata of the
3940
executable/library. The string then has the type `&'static str` meaning that
@@ -509,7 +510,7 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
509510
Section: MaybeOwned
510511
*/
511512

512-
/// A MaybeOwned is a string that can hold either a String or a &str.
513+
/// A `MaybeOwned` is a string that can hold either a `String` or a `&str`.
513514
/// This can be useful as an optimization when an allocation is sometimes
514515
/// needed but not always.
515516
pub enum MaybeOwned<'a> {
@@ -519,7 +520,7 @@ pub enum MaybeOwned<'a> {
519520
Owned(String)
520521
}
521522

522-
/// SendStr is a specialization of `MaybeOwned` to be sendable
523+
/// `SendStr` is a specialization of `MaybeOwned` to be sendable
523524
pub type SendStr = MaybeOwned<'static>;
524525

525526
impl<'a> MaybeOwned<'a> {

0 commit comments

Comments
 (0)