Skip to content

Commit 038f840

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 b403beb commit 038f840

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
@@ -81,7 +81,7 @@ impl GStr {
8181
/// This function is the equivalent of [`GStr::to_bytes`] except that it will retain the
8282
/// trailing nul terminator instead of chopping it off.
8383
#[inline]
84-
pub fn to_bytes_with_nul(&self) -> &[u8] {
84+
pub fn as_bytes_with_nul(&self) -> &[u8] {
8585
self.0.as_bytes()
8686
}
8787
// rustdoc-stripper-ignore-next
@@ -90,7 +90,7 @@ impl GStr {
9090
/// The returned slice will **not** contain the trailing nul terminator that this GLib
9191
/// string has.
9292
#[inline]
93-
pub fn to_bytes(&self) -> &[u8] {
93+
pub fn as_bytes(&self) -> &[u8] {
9494
self.as_str().as_bytes()
9595
}
9696
// rustdoc-stripper-ignore-next
@@ -119,7 +119,7 @@ impl GStr {
119119
/// Converts this GLib string to a C string slice.
120120
#[inline]
121121
pub fn as_c_str(&self) -> &CStr {
122-
unsafe { CStr::from_bytes_with_nul_unchecked(self.to_bytes_with_nul()) }
122+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
123123
}
124124

125125
#[doc(alias = "g_utf8_collate")]
@@ -142,7 +142,7 @@ impl GStr {
142142
/// use glib::{gstr, GStr, GString};
143143
///
144144
/// const MY_STRING: &GStr = gstr!("Hello");
145-
/// assert_eq!(MY_STRING.to_bytes_with_nul()[5], 0u8);
145+
/// assert_eq!(MY_STRING.as_bytes_with_nul()[5], 0u8);
146146
/// let owned: GString = MY_STRING.to_owned();
147147
/// assert_eq!(MY_STRING, owned);
148148
/// # }
@@ -271,7 +271,7 @@ impl AsRef<Path> for GStr {
271271

272272
impl AsRef<[u8]> for GStr {
273273
fn as_ref(&self) -> &[u8] {
274-
self.to_bytes()
274+
self.as_bytes()
275275
}
276276
}
277277

0 commit comments

Comments
 (0)