Skip to content

Commit 16f218b

Browse files
committed
Rename CStr::from_bytes to from_bytes_with_nul
1 parent a70ae2f commit 16f218b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libstd/ffi/c_str.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,16 @@ impl CStr {
449449
/// use std::ffi::CStr;
450450
///
451451
/// # fn main() {
452-
/// let cstr = CStr::from_bytes(b"hello\0");
452+
/// let cstr = CStr::from_bytes_with_nul(b"hello\0");
453453
/// assert!(cstr.is_some());
454454
/// # }
455455
/// ```
456456
#[unstable(feature = "cstr_from_bytes", reason = "recently added", issue = "0")]
457-
pub fn from_bytes<'a>(bytes: &'a [u8]) -> Option<&'a CStr> {
457+
pub fn from_bytes_with_nul<'a>(bytes: &'a [u8]) -> Option<&'a CStr> {
458458
if bytes.is_empty() || memchr::memchr(0, &bytes) != Some(bytes.len() - 1) {
459459
None
460460
} else {
461-
Some(unsafe { Self::from_bytes_unchecked(bytes) })
461+
Some(unsafe { Self::from_bytes_with_nul_unchecked(bytes) })
462462
}
463463
}
464464

@@ -477,13 +477,13 @@ impl CStr {
477477
/// # fn main() {
478478
/// unsafe {
479479
/// let cstring = CString::new("hello").unwrap();
480-
/// let cstr = CStr::from_bytes_unchecked(cstring.to_bytes_with_nul());
480+
/// let cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul());
481481
/// assert_eq!(cstr, &*cstring);
482482
/// }
483483
/// # }
484484
/// ```
485485
#[unstable(feature = "cstr_from_bytes", reason = "recently added", issue = "0")]
486-
pub unsafe fn from_bytes_unchecked<'a>(bytes: &'a [u8]) -> &'a CStr {
486+
pub unsafe fn from_bytes_with_nul_unchecked<'a>(bytes: &'a [u8]) -> &'a CStr {
487487
mem::transmute(bytes)
488488
}
489489

0 commit comments

Comments
 (0)