diff options
| author | arcnmx <arcnmx@users.noreply.github.com> | 2016-01-24 19:51:19 -0500 |
|---|---|---|
| committer | arcnmx <arcnmx@users.noreply.github.com> | 2016-02-23 01:37:53 -0500 |
| commit | 16f218b6006faa752925ca5934372c34f1eb2953 (patch) | |
| tree | 177d0e4458be5caeaa189c5fccb96a1d8262c312 /src | |
| parent | a70ae2ffb9a5dd08d916b9938eeca820486ba7a0 (diff) | |
| download | rust-16f218b6006faa752925ca5934372c34f1eb2953.tar.gz rust-16f218b6006faa752925ca5934372c34f1eb2953.zip | |
Rename CStr::from_bytes to from_bytes_with_nul
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index f50e906f14c..e3c51a74b09 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -449,16 +449,16 @@ impl CStr { /// use std::ffi::CStr; /// /// # fn main() { - /// let cstr = CStr::from_bytes(b"hello\0"); + /// let cstr = CStr::from_bytes_with_nul(b"hello\0"); /// assert!(cstr.is_some()); /// # } /// ``` #[unstable(feature = "cstr_from_bytes", reason = "recently added", issue = "0")] - pub fn from_bytes<'a>(bytes: &'a [u8]) -> Option<&'a CStr> { + pub fn from_bytes_with_nul<'a>(bytes: &'a [u8]) -> Option<&'a CStr> { if bytes.is_empty() || memchr::memchr(0, &bytes) != Some(bytes.len() - 1) { None } else { - Some(unsafe { Self::from_bytes_unchecked(bytes) }) + Some(unsafe { Self::from_bytes_with_nul_unchecked(bytes) }) } } @@ -477,13 +477,13 @@ impl CStr { /// # fn main() { /// unsafe { /// let cstring = CString::new("hello").unwrap(); - /// let cstr = CStr::from_bytes_unchecked(cstring.to_bytes_with_nul()); + /// let cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul()); /// assert_eq!(cstr, &*cstring); /// } /// # } /// ``` #[unstable(feature = "cstr_from_bytes", reason = "recently added", issue = "0")] - pub unsafe fn from_bytes_unchecked<'a>(bytes: &'a [u8]) -> &'a CStr { + pub unsafe fn from_bytes_with_nul_unchecked<'a>(bytes: &'a [u8]) -> &'a CStr { mem::transmute(bytes) } |
