Skip to content

Commit eae5d77

Browse files
Change variables names to be more consistent.
Changed all instances of `c_str` into `cstr` in the documentation examples. This is also consistent with the module source code.
1 parent cdedd26 commit eae5d77

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/libstd/ffi/c_str.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ impl CString {
572572
/// use std::ffi::{CString, CStr};
573573
///
574574
/// let c_string = CString::new(b"foo".to_vec()).expect("CString::new failed");
575-
/// let c_str = c_string.as_c_str();
576-
/// assert_eq!(c_str,
575+
/// let cstr = c_string.as_c_str();
576+
/// assert_eq!(cstr,
577577
/// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"));
578578
/// ```
579579
#[inline]
@@ -994,17 +994,17 @@ impl CStr {
994994
/// ```
995995
/// use std::ffi::CStr;
996996
///
997-
/// let c_str = CStr::from_bytes_with_nul(b"hello");
998-
/// assert!(c_str.is_err());
997+
/// let cstr = CStr::from_bytes_with_nul(b"hello");
998+
/// assert!(cstr.is_err());
999999
/// ```
10001000
///
10011001
/// Creating a `CStr` with an interior nul byte is an error:
10021002
///
10031003
/// ```
10041004
/// use std::ffi::CStr;
10051005
///
1006-
/// let c_str = CStr::from_bytes_with_nul(b"he\0llo\0");
1007-
/// assert!(c_str.is_err());
1006+
/// let cstr = CStr::from_bytes_with_nul(b"he\0llo\0");
1007+
/// assert!(cstr.is_err());
10081008
/// ```
10091009
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
10101010
pub fn from_bytes_with_nul(bytes: &[u8])
@@ -1111,8 +1111,8 @@ impl CStr {
11111111
/// ```
11121112
/// use std::ffi::CStr;
11131113
///
1114-
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
1115-
/// assert_eq!(c_str.to_bytes(), b"foo");
1114+
/// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
1115+
/// assert_eq!(cstr.to_bytes(), b"foo");
11161116
/// ```
11171117
#[inline]
11181118
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1137,8 +1137,8 @@ impl CStr {
11371137
/// ```
11381138
/// use std::ffi::CStr;
11391139
///
1140-
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
1141-
/// assert_eq!(c_str.to_bytes_with_nul(), b"foo\0");
1140+
/// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
1141+
/// assert_eq!(cstr.to_bytes_with_nul(), b"foo\0");
11421142
/// ```
11431143
#[inline]
11441144
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1164,8 +1164,8 @@ impl CStr {
11641164
/// ```
11651165
/// use std::ffi::CStr;
11661166
///
1167-
/// let c_str = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
1168-
/// assert_eq!(c_str.to_str(), Ok("foo"));
1167+
/// let cstr = CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed");
1168+
/// assert_eq!(cstr.to_str(), Ok("foo"));
11691169
/// ```
11701170
#[stable(feature = "cstr_to_str", since = "1.4.0")]
11711171
pub fn to_str(&self) -> Result<&str, str::Utf8Error> {
@@ -1205,9 +1205,9 @@ impl CStr {
12051205
/// use std::borrow::Cow;
12061206
/// use std::ffi::CStr;
12071207
///
1208-
/// let c_str = CStr::from_bytes_with_nul(b"Hello World\0")
1208+
/// let cstr = CStr::from_bytes_with_nul(b"Hello World\0")
12091209
/// .expect("CStr::from_bytes_with_nul failed");
1210-
/// assert_eq!(c_str.to_string_lossy(), Cow::Borrowed("Hello World"));
1210+
/// assert_eq!(cstr.to_string_lossy(), Cow::Borrowed("Hello World"));
12111211
/// ```
12121212
///
12131213
/// Calling `to_string_lossy` on a `CStr` containing invalid UTF-8:
@@ -1216,10 +1216,10 @@ impl CStr {
12161216
/// use std::borrow::Cow;
12171217
/// use std::ffi::CStr;
12181218
///
1219-
/// let c_str = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0")
1219+
/// let cstr = CStr::from_bytes_with_nul(b"Hello \xF0\x90\x80World\0")
12201220
/// .expect("CStr::from_bytes_with_nul failed");
12211221
/// assert_eq!(
1222-
/// c_str.to_string_lossy(),
1222+
/// cstr.to_string_lossy(),
12231223
/// Cow::Owned(String::from("Hello �World")) as Cow<'_, str>
12241224
/// );
12251225
/// ```

0 commit comments

Comments
 (0)