Skip to content

Commit 291607c

Browse files
jf2048sdroege
authored andcommitted
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 45423ea commit 291607c

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
@@ -83,7 +83,7 @@ impl GStr {
8383
/// This function is the equivalent of [`GStr::to_bytes`] except that it will retain the
8484
/// trailing nul terminator instead of chopping it off.
8585
#[inline]
86-
pub fn to_bytes_with_nul(&self) -> &[u8] {
86+
pub fn as_bytes_with_nul(&self) -> &[u8] {
8787
self.0.as_bytes()
8888
}
8989
// rustdoc-stripper-ignore-next
@@ -92,7 +92,7 @@ impl GStr {
9292
/// The returned slice will **not** contain the trailing nul terminator that this GLib
9393
/// string has.
9494
#[inline]
95-
pub fn to_bytes(&self) -> &[u8] {
95+
pub fn as_bytes(&self) -> &[u8] {
9696
self.as_str().as_bytes()
9797
}
9898
// rustdoc-stripper-ignore-next
@@ -121,7 +121,7 @@ impl GStr {
121121
/// Converts this GLib string to a C string slice.
122122
#[inline]
123123
pub fn as_c_str(&self) -> &CStr {
124-
unsafe { CStr::from_bytes_with_nul_unchecked(self.to_bytes_with_nul()) }
124+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
125125
}
126126

127127
#[doc(alias = "g_utf8_collate")]
@@ -144,7 +144,7 @@ impl GStr {
144144
/// use glib::{gstr, GStr, GString};
145145
///
146146
/// const MY_STRING: &GStr = gstr!("Hello");
147-
/// assert_eq!(MY_STRING.to_bytes_with_nul()[5], 0u8);
147+
/// assert_eq!(MY_STRING.as_bytes_with_nul()[5], 0u8);
148148
/// let owned: GString = MY_STRING.to_owned();
149149
/// assert_eq!(MY_STRING, owned);
150150
/// # }
@@ -273,7 +273,7 @@ impl AsRef<Path> for GStr {
273273

274274
impl AsRef<[u8]> for GStr {
275275
fn as_ref(&self) -> &[u8] {
276-
self.to_bytes()
276+
self.as_bytes()
277277
}
278278
}
279279

0 commit comments

Comments
 (0)