-
Notifications
You must be signed in to change notification settings - Fork 13k
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
collections: update docs of slice get() and friends #39150
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,15 +342,22 @@ impl<T> [T] { | |
core_slice::SliceExt::last_mut(self) | ||
} | ||
|
||
/// Returns the element of a slice at the given index, or `None` if the | ||
/// index is out of bounds. | ||
/// Returns a reference to an element or subslice depending on the type of | ||
/// index. | ||
/// | ||
/// - If given a position, returns a reference to the element at that | ||
/// position or `None` if out of bounds. | ||
/// - If given a range, returns the subslice corresponding to that range, | ||
/// or `None` if out of bounds. | ||
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. Can you add |
||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// let v = [10, 40, 30]; | ||
/// assert_eq!(Some(&40), v.get(1)); | ||
/// assert_eq!(Some(&[10, 40][..]), v.get(0..2)); | ||
/// assert_eq!(None, v.get(3)); | ||
/// assert_eq!(None, v.get(0..4)); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[inline] | ||
|
@@ -360,7 +367,10 @@ impl<T> [T] { | |
core_slice::SliceExt::get(self, index) | ||
} | ||
|
||
/// Returns a mutable reference to the element at the given index. | ||
/// Returns a mutable reference to an element or subslice depending on the | ||
/// type of index (see [`get()`]) or `None` if the index is out of bounds. | ||
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. Can you add |
||
/// | ||
/// [`get()`]: #method.get | ||
/// | ||
/// # Examples | ||
/// | ||
|
@@ -372,7 +382,6 @@ impl<T> [T] { | |
/// } | ||
/// assert_eq!(x, &[0, 42, 2]); | ||
/// ``` | ||
/// or `None` if the index is out of bounds | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[inline] | ||
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output> | ||
|
@@ -381,8 +390,8 @@ impl<T> [T] { | |
core_slice::SliceExt::get_mut(self, index) | ||
} | ||
|
||
/// Returns a pointer to the element at the given index, without doing | ||
/// bounds checking. So use it very carefully! | ||
/// Returns a reference to an element or subslice, without doing bounds | ||
/// checking. So use it very carefully! | ||
/// | ||
/// # Examples | ||
/// | ||
|
@@ -401,8 +410,8 @@ impl<T> [T] { | |
core_slice::SliceExt::get_unchecked(self, index) | ||
} | ||
|
||
/// Returns an unsafe mutable pointer to the element in index. So use it | ||
/// very carefully! | ||
/// Returns a mutable reference to an element or subslice, without doing | ||
/// bounds checking. So use it very carefully! | ||
/// | ||
/// # Examples | ||
/// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you add
None
url please?