Skip to content

Commit 62ef6e3

Browse files
committed
glib: rename GStr::to_bytes to as_bytes
For consistency with str::as_bytes. Since we always store the length of the slice we can always do a const conversion like str does.
1 parent fab9c8e commit 62ef6e3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

glib/src/gstring.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl GStr {
6464
/// This function is the equivalent of [`GStr::to_bytes`] except that it will retain the
6565
/// trailing nul terminator instead of chopping it off.
6666
#[inline]
67-
pub fn to_bytes_with_nul(&self) -> &[u8] {
67+
pub fn as_bytes_with_nul(&self) -> &[u8] {
6868
self.0.as_bytes()
6969
}
7070
// rustdoc-stripper-ignore-next
@@ -73,7 +73,7 @@ impl GStr {
7373
/// The returned slice will **not** contain the trailing nul terminator that this GLib
7474
/// string has.
7575
#[inline]
76-
pub fn to_bytes(&self) -> &[u8] {
76+
pub fn as_bytes(&self) -> &[u8] {
7777
self.as_str().as_bytes()
7878
}
7979
// rustdoc-stripper-ignore-next
@@ -102,7 +102,7 @@ impl GStr {
102102
/// Converts this GLib string to a C string slice.
103103
#[inline]
104104
pub fn as_c_str(&self) -> &CStr {
105-
unsafe { CStr::from_bytes_with_nul_unchecked(self.to_bytes_with_nul()) }
105+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
106106
}
107107
}
108108

@@ -119,7 +119,7 @@ impl GStr {
119119
/// use glib::{gstr, GStr, GString};
120120
///
121121
/// const MY_STRING: &GStr = gstr!("Hello");
122-
/// assert_eq!(MY_STRING.to_bytes_with_nul()[5], 0u8);
122+
/// assert_eq!(MY_STRING.as_bytes_with_nul()[5], 0u8);
123123
/// let owned: GString = MY_STRING.to_owned();
124124
/// assert_eq!(MY_STRING, owned);
125125
/// # }
@@ -248,7 +248,7 @@ impl AsRef<Path> for GStr {
248248

249249
impl AsRef<[u8]> for GStr {
250250
fn as_ref(&self) -> &[u8] {
251-
self.to_bytes()
251+
self.as_bytes()
252252
}
253253
}
254254

0 commit comments

Comments
 (0)