diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-09-10 14:03:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-10 14:03:30 +0200 |
| commit | 329ed4affe07cb935dd3c28eade8673b53eeaae2 (patch) | |
| tree | a57b8721fd69bede9e1bae7131659d5cf4a7636d /src/liballoc | |
| parent | 485847dd701b5d2161fb8b13730d93e14d6bcfcc (diff) | |
| parent | 6c8993532c7799c745247fb7dc6293156e5c5b05 (diff) | |
| download | rust-329ed4affe07cb935dd3c28eade8673b53eeaae2.tar.gz rust-329ed4affe07cb935dd3c28eade8673b53eeaae2.zip | |
Rollup merge of #44457 - napen123:master, r=frewsxcv
Add doc examples for str::as_bytes_mut Fixes #44427
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 79b2bbce2af..c1252b219c4 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -297,6 +297,34 @@ impl str { /// [`str::from_utf8_mut`] function. /// /// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// let mut s = String::from("Hello"); + /// let bytes = unsafe { s.as_bytes_mut() }; + /// + /// assert_eq!(b"Hello", bytes); + /// ``` + /// + /// Mutability: + /// + /// ``` + /// let mut s = String::from("🗻∈🌏"); + /// + /// unsafe { + /// let bytes = s.as_bytes_mut(); + /// + /// bytes[0] = 0xF0; + /// bytes[1] = 0x9F; + /// bytes[2] = 0x8D; + /// bytes[3] = 0x94; + /// } + /// + /// assert_eq!("🍔∈🌏", s); + /// ``` #[stable(feature = "str_mut_extras", since = "1.20.0")] #[inline(always)] pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] { |
