@@ -16,24 +16,25 @@ Unicode string manipulation (`str` type)
16
16
17
17
Rust's string type is one of the core primitive types of the language. While
18
18
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`.
21
22
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.
26
27
27
- As an example, here's the one kind of string.
28
+ As an example, here's some code that uses a string.
28
29
29
30
```rust
30
31
fn main() {
31
32
let borrowed_string = "This string is borrowed with the 'static lifetime";
32
33
}
33
34
```
34
35
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.
37
38
38
39
String literals are allocated statically in the rodata of the
39
40
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> {
509
510
Section: MaybeOwned
510
511
*/
511
512
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` .
513
514
/// This can be useful as an optimization when an allocation is sometimes
514
515
/// needed but not always.
515
516
pub enum MaybeOwned < ' a > {
@@ -519,7 +520,7 @@ pub enum MaybeOwned<'a> {
519
520
Owned ( String )
520
521
}
521
522
522
- /// SendStr is a specialization of `MaybeOwned` to be sendable
523
+ /// ` SendStr` is a specialization of `MaybeOwned` to be sendable
523
524
pub type SendStr = MaybeOwned < ' static > ;
524
525
525
526
impl < ' a > MaybeOwned < ' a > {
0 commit comments