Rollup merge of #32099 - bluss:doc-string-slicing, r=alexcrichton
Clarify documentation for string slicing (Index impls) Clarify documentation for string slicing (Index impls) - Mention the sugared syntax for the implementations, since it's not apparent from the docs that `Index<Range<usize>>` corresponds to `&self[a..b]`. - Be specific in that start <= end and end <= len This is just one fix in response to #32057
This commit is contained in:
commit
13ba07b854
1 changed files with 51 additions and 13 deletions
|
@ -1311,13 +1311,19 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements substring slicing with syntax `&self[begin .. end]`.
|
||||||
|
///
|
||||||
/// Returns a slice of the given string from the byte range
|
/// Returns a slice of the given string from the byte range
|
||||||
/// [`begin`..`end`).
|
/// [`begin`..`end`).
|
||||||
///
|
///
|
||||||
/// This operation is `O(1)`.
|
/// This operation is `O(1)`.
|
||||||
///
|
///
|
||||||
/// Panics when `begin` and `end` do not point to valid characters
|
/// # Panics
|
||||||
/// or point beyond the last character of the string.
|
///
|
||||||
|
/// Panics if `begin` or `end` does not point to the starting
|
||||||
|
/// byte offset of a character (as defined by `is_char_boundary`).
|
||||||
|
/// Requires that `begin <= end` and `end <= len` where `len` is the
|
||||||
|
/// length of the string.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -1353,8 +1359,20 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements mutable substring slicing with syntax
|
||||||
|
/// `&mut self[begin .. end]`.
|
||||||
|
///
|
||||||
/// Returns a mutable slice of the given string from the byte range
|
/// Returns a mutable slice of the given string from the byte range
|
||||||
/// [`begin`..`end`).
|
/// [`begin`..`end`).
|
||||||
|
///
|
||||||
|
/// This operation is `O(1)`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if `begin` or `end` does not point to the starting
|
||||||
|
/// byte offset of a character (as defined by `is_char_boundary`).
|
||||||
|
/// Requires that `begin <= end` and `end <= len` where `len` is the
|
||||||
|
/// length of the string.
|
||||||
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
||||||
impl ops::IndexMut<ops::Range<usize>> for str {
|
impl ops::IndexMut<ops::Range<usize>> for str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1370,13 +1388,12 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a slice of the string from the beginning to byte
|
/// Implements substring slicing with syntax `&self[.. end]`.
|
||||||
|
///
|
||||||
|
/// Returns a slice of the string from the beginning to byte offset
|
||||||
/// `end`.
|
/// `end`.
|
||||||
///
|
///
|
||||||
/// Equivalent to `self[0 .. end]`.
|
/// Equivalent to `&self[0 .. end]`.
|
||||||
///
|
|
||||||
/// Panics when `end` does not point to a valid character, or is
|
|
||||||
/// out of bounds.
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeTo<usize>> for str {
|
impl ops::Index<ops::RangeTo<usize>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
@ -1392,8 +1409,12 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a mutable slice of the string from the beginning to byte
|
/// Implements mutable substring slicing with syntax `&mut self[.. end]`.
|
||||||
|
///
|
||||||
|
/// Returns a mutable slice of the string from the beginning to byte offset
|
||||||
/// `end`.
|
/// `end`.
|
||||||
|
///
|
||||||
|
/// Equivalent to `&mut self[0 .. end]`.
|
||||||
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
||||||
impl ops::IndexMut<ops::RangeTo<usize>> for str {
|
impl ops::IndexMut<ops::RangeTo<usize>> for str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1407,12 +1428,12 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a slice of the string from `begin` to its end.
|
/// Implements substring slicing with syntax `&self[begin ..]`.
|
||||||
///
|
///
|
||||||
/// Equivalent to `self[begin .. self.len()]`.
|
/// Returns a slice of the string from byte offset `begin`
|
||||||
|
/// to the end of the string.
|
||||||
///
|
///
|
||||||
/// Panics when `begin` does not point to a valid character, or is
|
/// Equivalent to `&self[begin .. len]`.
|
||||||
/// out of bounds.
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFrom<usize>> for str {
|
impl ops::Index<ops::RangeFrom<usize>> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
@ -1428,7 +1449,12 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a slice of the string from `begin` to its end.
|
/// Implements mutable substring slicing with syntax `&mut self[begin ..]`.
|
||||||
|
///
|
||||||
|
/// Returns a mutable slice of the string from byte offset `begin`
|
||||||
|
/// to the end of the string.
|
||||||
|
///
|
||||||
|
/// Equivalent to `&mut self[begin .. len]`.
|
||||||
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
||||||
impl ops::IndexMut<ops::RangeFrom<usize>> for str {
|
impl ops::IndexMut<ops::RangeFrom<usize>> for str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1443,6 +1469,12 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements substring slicing with syntax `&self[..]`.
|
||||||
|
///
|
||||||
|
/// Returns a slice of the whole string. This operation can
|
||||||
|
/// never panic.
|
||||||
|
///
|
||||||
|
/// Equivalent to `&self[0 .. len]`.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ops::Index<ops::RangeFull> for str {
|
impl ops::Index<ops::RangeFull> for str {
|
||||||
type Output = str;
|
type Output = str;
|
||||||
|
@ -1453,6 +1485,12 @@ mod traits {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements mutable substring slicing with syntax `&mut self[..]`.
|
||||||
|
///
|
||||||
|
/// Returns a mutable slice of the whole string. This operation can
|
||||||
|
/// never panic.
|
||||||
|
///
|
||||||
|
/// Equivalent to `&mut self[0 .. len]`.
|
||||||
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
|
||||||
impl ops::IndexMut<ops::RangeFull> for str {
|
impl ops::IndexMut<ops::RangeFull> for str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue