Skip to content

Commit f79c794

Browse files
authored
Rollup merge of rust-lang#40682 - TigleyM:str_doc, r=steveklabnik
Update docs for std::str fixes rust-lang#29375 I noticed there are docs for the `str` primitive type, which contained extensive examples, so my additions give a more general explanation of `&str`. But please let me know if something can be explained more or changed. r? @steveklabnik
2 parents 5cf960d + da74e86 commit f79c794

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/libcollections/str.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,28 @@
1010

1111
//! Unicode string slices.
1212
//!
13+
//! The `&str` type is one of the two main string types, the other being `String`.
14+
//! Unlike its `String` counterpart, its contents are borrowed.
15+
//!
16+
//! # Basic Usage
17+
//!
18+
//! A basic string declaration of `&str` type:
19+
//!
20+
//! ```
21+
//! let hello_world = "Hello, World!";
22+
//! ```
23+
//!
24+
//! Here we have declared a string literal, also known as a string slice.
25+
//! String literals have a static lifetime, which means the string `hello_world`
26+
//! is guaranteed to be valid for the duration of the entire program.
27+
//! We can explicitly specify `hello_world`'s lifetime as well:
28+
//!
29+
//! ```
30+
//! let hello_world: &'static str = "Hello, world!";
31+
//! ```
32+
//!
1333
//! *[See also the `str` primitive type](../../std/primitive.str.html).*
1434
15-
1635
#![stable(feature = "rust1", since = "1.0.0")]
1736

1837
// Many of the usings in this module are only used in the test configuration.

0 commit comments

Comments
 (0)