diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-08-07 22:30:39 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-08-09 11:44:21 -0700 |
| commit | c25ddf21f18c3eeeaea2a4dffd70d2f6183068b5 (patch) | |
| tree | 9715e57405ae14bd7877dec129bce733daf72dc1 /src/liballoc | |
| parent | cc4ff8f4d169562ff4ae22b94197a191215e6d56 (diff) | |
| parent | c5e2051f070c01241f68720a92a0957bcb070597 (diff) | |
| download | rust-c25ddf21f18c3eeeaea2a4dffd70d2f6183068b5.tar.gz rust-c25ddf21f18c3eeeaea2a4dffd70d2f6183068b5.zip | |
Merge remote-tracking branch 'origin/master' into gen
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/allocator.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/str.rs | 43 |
2 files changed, 33 insertions, 11 deletions
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs index 66e0bf81c90..42111301a9f 100644 --- a/src/liballoc/allocator.rs +++ b/src/liballoc/allocator.rs @@ -215,6 +215,7 @@ impl Layout { /// of each element in the array. /// /// On arithmetic overflow, returns `None`. + #[inline] pub fn repeat(&self, n: usize) -> Option<(Self, usize)> { let padded_size = match self.size.checked_add(self.padding_needed_for(self.align)) { None => return None, diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 4df13c509a8..80317cd763b 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -273,7 +273,10 @@ impl str { core_str::StrExt::is_char_boundary(self, index) } - /// Converts a string slice to a byte slice. + /// Converts a string slice to a byte slice. To convert the byte slice back + /// into a string slice, use the [`str::from_utf8`] function. + /// + /// [`str::from_utf8`]: ./str/fn.from_utf8.html /// /// # Examples /// @@ -289,7 +292,11 @@ impl str { core_str::StrExt::as_bytes(self) } - /// Converts a mutable string slice to a mutable byte slice. + /// Converts a mutable string slice to a mutable byte slice. To convert the + /// mutable byte slice back into a mutable string slice, use the + /// [`str::from_utf8_mut`] function. + /// + /// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html #[stable(feature = "str_mut_extras", since = "1.20.0")] #[inline(always)] pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] { @@ -328,11 +335,16 @@ impl str { /// # Examples /// /// ``` - /// let v = "🗻∈🌏"; + /// let mut v = String::from("🗻∈🌏"); + /// /// 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()); + /// + /// // 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 +363,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")] @@ -563,12 +580,16 @@ impl str { /// Basic usage: /// /// ``` - /// let mut s = "Per Martin-Löf".to_string(); - /// - /// let (first, last) = s.split_at_mut(3); + /// use std::ascii::AsciiExt; /// - /// assert_eq!("Per", first); - /// assert_eq!(" Martin-Löf", last); + /// let mut s = "Per Martin-Löf".to_string(); + /// { + /// let (first, last) = s.split_at_mut(3); + /// first.make_ascii_uppercase(); + /// assert_eq!("PER", first); + /// assert_eq!(" Martin-Löf", last); + /// } + /// assert_eq!("PER Martin-Löf", s); /// ``` #[inline] #[stable(feature = "str_split_at", since = "1.4.0")] |
