@@ -273,7 +273,10 @@ impl str {
273
273
core_str:: StrExt :: is_char_boundary ( self , index)
274
274
}
275
275
276
- /// Converts a string slice to a byte slice.
276
+ /// Converts a string slice to a byte slice. To convert the byte slice back
277
+ /// into a string slice, use the [`str::from_utf8`] function.
278
+ ///
279
+ /// [`str::from_utf8`]: ./str/fn.from_utf8.html
277
280
///
278
281
/// # Examples
279
282
///
@@ -289,7 +292,11 @@ impl str {
289
292
core_str:: StrExt :: as_bytes ( self )
290
293
}
291
294
292
- /// Converts a mutable string slice to a mutable byte slice.
295
+ /// Converts a mutable string slice to a mutable byte slice. To convert the
296
+ /// mutable byte slice back into a mutable string slice, use the
297
+ /// [`str::from_utf8_mut`] function.
298
+ ///
299
+ /// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
293
300
#[ stable( feature = "str_mut_extras" , since = "1.20.0" ) ]
294
301
#[ inline( always) ]
295
302
pub unsafe fn as_bytes_mut ( & mut self ) -> & mut [ u8 ] {
@@ -328,11 +335,16 @@ impl str {
328
335
/// # Examples
329
336
///
330
337
/// ```
331
- /// let v = "🗻∈🌏";
338
+ /// let mut v = String::from("🗻∈🌏");
339
+ ///
332
340
/// assert_eq!(Some("🗻"), v.get(0..4));
333
- /// assert!(v.get(1..).is_none());
334
- /// assert!(v.get(..8).is_none());
335
- /// assert!(v.get(..42).is_none());
341
+ ///
342
+ /// // indices not on UTF-8 sequence boundaries
343
+ /// assert!(v.get_mut(1..).is_none());
344
+ /// assert!(v.get_mut(..8).is_none());
345
+ ///
346
+ /// // out of bounds
347
+ /// assert!(v.get_mut(..42).is_none());
336
348
/// ```
337
349
#[ stable( feature = "str_checked_slicing" , since = "1.20.0" ) ]
338
350
#[ inline]
@@ -351,9 +363,14 @@ impl str {
351
363
///
352
364
/// ```
353
365
/// let mut v = String::from("🗻∈🌏");
366
+ ///
354
367
/// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
368
+ ///
369
+ /// // indices not on UTF-8 sequence boundaries
355
370
/// assert!(v.get_mut(1..).is_none());
356
371
/// assert!(v.get_mut(..8).is_none());
372
+ ///
373
+ /// // out of bounds
357
374
/// assert!(v.get_mut(..42).is_none());
358
375
/// ```
359
376
#[ stable( feature = "str_checked_slicing" , since = "1.20.0" ) ]
@@ -563,12 +580,16 @@ impl str {
563
580
/// Basic usage:
564
581
///
565
582
/// ```
566
- /// let mut s = "Per Martin-Löf".to_string();
567
- ///
568
- /// let (first, last) = s.split_at_mut(3);
583
+ /// use std::ascii::AsciiExt;
569
584
///
570
- /// assert_eq!("Per", first);
571
- /// assert_eq!(" Martin-Löf", last);
585
+ /// let mut s = "Per Martin-Löf".to_string();
586
+ /// {
587
+ /// let (first, last) = s.split_at_mut(3);
588
+ /// first.make_ascii_uppercase();
589
+ /// assert_eq!("PER", first);
590
+ /// assert_eq!(" Martin-Löf", last);
591
+ /// }
592
+ /// assert_eq!("PER Martin-Löf", s);
572
593
/// ```
573
594
#[ inline]
574
595
#[ stable( feature = "str_split_at" , since = "1.4.0" ) ]
0 commit comments