diff options
| author | bors <bors@rust-lang.org> | 2017-06-08 03:46:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-08 03:46:16 +0000 |
| commit | e1fa8de0fb900026a1a126928940e4eea3b729b5 (patch) | |
| tree | ceadfbdc47590ae898d8c6396895d677f41f84ba /src/libstd | |
| parent | d8d5592596b75ff1b810c15944e6bac57ab9c15a (diff) | |
| parent | 13ae42fb205e06320647b3f508462c46a2644c07 (diff) | |
| download | rust-e1fa8de0fb900026a1a126928940e4eea3b729b5.tar.gz rust-e1fa8de0fb900026a1a126928940e4eea3b729b5.zip | |
Auto merge of #42522 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests - Successful merges: #42470, #42490, #42497, #42510, #42512 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 60 | ||||
| -rw-r--r-- | src/libstd/panic.rs | 2 |
2 files changed, 61 insertions, 1 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 1167c39dba8..2d78f0511d6 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -288,6 +288,26 @@ impl CString { /// Failure to call [`from_raw`] will lead to a memory leak. /// /// [`from_raw`]: #method.from_raw + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// + /// let ptr = c_string.into_raw(); + /// + /// unsafe { + /// assert_eq!(b'f', *ptr as u8); + /// assert_eq!(b'o', *ptr.offset(1) as u8); + /// assert_eq!(b'o', *ptr.offset(2) as u8); + /// assert_eq!(b'\0', *ptr.offset(3) as u8); + /// + /// // retake pointer to free memory + /// let _ = CString::from_raw(ptr); + /// } + /// ``` #[stable(feature = "cstr_memory", since = "1.4.0")] pub fn into_raw(self) -> *mut c_char { Box::into_raw(self.into_inner()) as *mut c_char @@ -311,6 +331,16 @@ impl CString { /// /// The returned buffer does **not** contain the trailing nul separator and /// it is guaranteed to not have any interior nul bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.into_bytes(); + /// assert_eq!(bytes, vec![b'f', b'o', b'o']); + /// ``` #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_bytes(self) -> Vec<u8> { let mut vec = self.into_inner().into_vec(); @@ -323,6 +353,16 @@ impl CString { /// includes the trailing nul byte. /// /// [`into_bytes`]: #method.into_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.into_bytes_with_nul(); + /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']); + /// ``` #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_bytes_with_nul(self) -> Vec<u8> { self.into_inner().into_vec() @@ -332,6 +372,16 @@ impl CString { /// /// The returned slice does **not** contain the trailing nul separator and /// it is guaranteed to not have any interior nul bytes. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes(); + /// assert_eq!(bytes, &[b'f', b'o', b'o']); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes(&self) -> &[u8] { &self.inner[..self.inner.len() - 1] @@ -341,6 +391,16 @@ impl CString { /// includes the trailing nul byte. /// /// [`as_bytes`]: #method.as_bytes + /// + /// # Examples + /// + /// ``` + /// use std::ffi::CString; + /// + /// let c_string = CString::new("foo").unwrap(); + /// let bytes = c_string.as_bytes_with_nul(); + /// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_bytes_with_nul(&self) -> &[u8] { &self.inner diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index f99634ecac2..58356bc43ee 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -112,7 +112,7 @@ pub trait UnwindSafe {} /// This is a "helper marker trait" used to provide impl blocks for the /// `UnwindSafe` trait, for more information see that documentation. #[stable(feature = "catch_unwind", since = "1.9.0")] -#[rustc_on_unimplemented = "the type {Self} contains interior mutability \ +#[rustc_on_unimplemented = "the type {Self} may contain interior mutability \ and a reference may not be safely transferrable \ across a catch_unwind boundary"] pub trait RefUnwindSafe {} |
