mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Indicate why str::{get,get_mut} examples return None.
This commit is contained in:
parent
c523b3f954
commit
ea6a657175
@ -328,11 +328,16 @@ impl str {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let v = "🗻∈🌏";
|
||||
/// assert_eq!(Some("🗻"), v.get(0..4));
|
||||
/// assert!(v.get(1..).is_none());
|
||||
/// assert!(v.get(..8).is_none());
|
||||
/// assert!(v.get(..42).is_none());
|
||||
/// let mut v = String::from("🗻∈🌏");
|
||||
///
|
||||
/// assert_eq!(Some("🗻"), v.get(0..4);
|
||||
///
|
||||
/// // indices not on UTF-8 sequence boundaries
|
||||
/// assert!(v.get_mut(1..).is_none());
|
||||
/// assert!(v.get_mut(..8).is_none());
|
||||
///
|
||||
/// // out of bounds
|
||||
/// assert!(v.get_mut(..42).is_none());
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
#[inline]
|
||||
@ -351,9 +356,14 @@ impl str {
|
||||
///
|
||||
/// ```
|
||||
/// let mut v = String::from("🗻∈🌏");
|
||||
///
|
||||
/// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
|
||||
///
|
||||
/// // indices not on UTF-8 sequence boundaries
|
||||
/// assert!(v.get_mut(1..).is_none());
|
||||
/// assert!(v.get_mut(..8).is_none());
|
||||
///
|
||||
/// // out of bounds
|
||||
/// assert!(v.get_mut(..42).is_none());
|
||||
/// ```
|
||||
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user