-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Update docs for std::str #40682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update docs for std::str #40682
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,28 @@ | |
|
||
//! Unicode string slices. | ||
//! | ||
//! The `&str` type is one of the two main string types, the other being `String`. | ||
//! Unlike its `String` counterpart, its contents are borrowed and therefore | ||
//! cannot be moved someplace else. | ||
//! | ||
//! # Basic Usage | ||
//! A basic string declaration of `&str` type: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you insert a Also, I might say "Defining a variable with the type |
||
//! | ||
//! ``` | ||
//! let hello_world = "Hello, World!"; | ||
//! ``` | ||
//! | ||
//! Here we have declared a string literal, also known as a string slice. | ||
//! String literals have a static lifetime, which means the string `hello_world` | ||
//! is guaranteed to be valid for the duration of the entire program. | ||
//! We can explicitly specify `hello_world`'s lifetime as well: | ||
//! | ||
//! ``` | ||
//! let hello_world:&'static str = "Hello, world!"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
//! ``` | ||
//! | ||
//! *[See also the `str` primitive type](../../std/primitive.str.html).* | ||
|
||
|
||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
// Many of the usings in this module are only used in the test configuration. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty solid, but I would probably end up just ending the sentence after "borrowed", as you can move
&str
values, just not what they point to, which is very tricky and not really relevant here, IMHO.