Skip to content

Commit 67867c6

Browse files
committed
Update docs for std::str
1 parent 6eb9960 commit 67867c6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libcollections/str.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ pub use std_unicode::str::SplitWhitespace;
5959
#[stable(feature = "rust1", since = "1.0.0")]
6060
pub use core::str::pattern;
6161

62+
/// Unicode string slices.
63+
///
64+
/// The `&str` type is one of the two main string types, the other being `String`. Unlike its `String` counterpart, its contents
65+
/// are borrowed and therefore cannot be moved someplace else.
66+
///
67+
/// # Basic Usage
68+
/// A basic string declaration of `&str` type:
69+
///
70+
/// ```
71+
/// let hello_world = "Hello, World!";
72+
/// ```
73+
/// Here we have declared a string literal, also known as a string slice.
74+
/// String literals have a static lifetime, which means the string `hello_world`
75+
/// is guaranteed to be valid for the duration of the entire program. We can explicitly specify
76+
/// `hello_world`'s lifetime as well:
77+
///
78+
/// ```
79+
/// let hello_world:&'static str = "Hello, world!";
80+
/// ```
81+
///
82+
6283
#[unstable(feature = "slice_concat_ext",
6384
reason = "trait should not have to exist",
6485
issue = "27747")]

0 commit comments

Comments
 (0)