@@ -57,11 +57,11 @@ impl fmt::Display for BStr {
57
57
/// # use kernel::{prelude::fmt, b_str, str::{BStr, CString}};
58
58
/// let ascii = b_str!("Hello, BStr!");
59
59
/// let s = CString::try_from_fmt(fmt!("{ascii}"))?;
60
- /// assert_eq!(s.as_bytes (), "Hello, BStr!".as_bytes());
60
+ /// assert_eq!(s.to_bytes (), "Hello, BStr!".as_bytes());
61
61
///
62
62
/// let non_ascii = b_str!("🦀");
63
63
/// let s = CString::try_from_fmt(fmt!("{non_ascii}"))?;
64
- /// assert_eq!(s.as_bytes (), "\\xf0\\x9f\\xa6\\x80".as_bytes());
64
+ /// assert_eq!(s.to_bytes (), "\\xf0\\x9f\\xa6\\x80".as_bytes());
65
65
/// # Ok::<(), kernel::error::Error>(())
66
66
/// ```
67
67
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -89,11 +89,11 @@ impl fmt::Debug for BStr {
89
89
/// // Embedded double quotes are escaped.
90
90
/// let ascii = b_str!("Hello, \"BStr\"!");
91
91
/// let s = CString::try_from_fmt(fmt!("{ascii:?}"))?;
92
- /// assert_eq!(s.as_bytes (), "\"Hello, \\\"BStr\\\"!\"".as_bytes());
92
+ /// assert_eq!(s.to_bytes (), "\"Hello, \\\"BStr\\\"!\"".as_bytes());
93
93
///
94
94
/// let non_ascii = b_str!("😺");
95
95
/// let s = CString::try_from_fmt(fmt!("{non_ascii:?}"))?;
96
- /// assert_eq!(s.as_bytes (), "\"\\xf0\\x9f\\x98\\xba\"".as_bytes());
96
+ /// assert_eq!(s.to_bytes (), "\"\\xf0\\x9f\\x98\\xba\"".as_bytes());
97
97
/// # Ok::<(), kernel::error::Error>(())
98
98
/// ```
99
99
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -465,15 +465,15 @@ impl fmt::Display for CStr {
465
465
/// # use kernel::str::CString;
466
466
/// let penguin = c_str!("🐧");
467
467
/// let s = CString::try_from_fmt(fmt!("{penguin}"))?;
468
- /// assert_eq!(s.as_bytes_with_nul (), "\\xf0\\x9f\\x90\\xa7\0".as_bytes());
468
+ /// assert_eq!(s.to_bytes_with_nul (), "\\xf0\\x9f\\x90\\xa7\0".as_bytes());
469
469
///
470
470
/// let ascii = c_str!("so \"cool\"");
471
471
/// let s = CString::try_from_fmt(fmt!("{ascii}"))?;
472
- /// assert_eq!(s.as_bytes_with_nul (), "so \"cool\"\0".as_bytes());
472
+ /// assert_eq!(s.to_bytes_with_nul (), "so \"cool\"\0".as_bytes());
473
473
/// # Ok::<(), kernel::error::Error>(())
474
474
/// ```
475
475
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
476
- for & c in self . as_bytes ( ) {
476
+ for & c in self . to_bytes ( ) {
477
477
if ( 0x20 ..0x7f ) . contains ( & c) {
478
478
// Printable character.
479
479
f. write_char ( c as char ) ?;
@@ -874,11 +874,11 @@ impl fmt::Write for Formatter {
874
874
/// use kernel::{str::CString, prelude::fmt};
875
875
///
876
876
/// let s = CString::try_from_fmt(fmt!("{}{}{}", "abc", 10, 20))?;
877
- /// assert_eq!(s.as_bytes_with_nul (), "abc1020\0".as_bytes());
877
+ /// assert_eq!(s.to_bytes_with_nul (), "abc1020\0".as_bytes());
878
878
///
879
879
/// let tmp = "testing";
880
880
/// let s = CString::try_from_fmt(fmt!("{tmp}{}", 123))?;
881
- /// assert_eq!(s.as_bytes_with_nul (), "testing123\0".as_bytes());
881
+ /// assert_eq!(s.to_bytes_with_nul (), "testing123\0".as_bytes());
882
882
///
883
883
/// // This fails because it has an embedded `NUL` byte.
884
884
/// let s = CString::try_from_fmt(fmt!("a\0b{}", 123));
@@ -948,7 +948,7 @@ impl<'a> TryFrom<&'a CStr> for CString {
948
948
fn try_from ( cstr : & ' a CStr ) -> Result < CString , AllocError > {
949
949
let mut buf = KVec :: new ( ) ;
950
950
951
- buf. extend_from_slice ( cstr. as_bytes_with_nul ( ) , GFP_KERNEL ) ?;
951
+ buf. extend_from_slice ( cstr. to_bytes_with_nul ( ) , GFP_KERNEL ) ?;
952
952
953
953
// INVARIANT: The `CStr` and `CString` types have the same invariants for
954
954
// the string data, and we copied it over without changes.
0 commit comments