Skip to content

Commit afc7b27

Browse files
committed
glib: Change GStr::from_bytes_with_nul_unchecked to from_utf8_with_nul_unchecked
1 parent 942531d commit afc7b27

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

glib/src/gstring.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl GStr {
3333
pub fn from_str_with_nul(s: &str) -> Result<&Self, std::ffi::FromBytesWithNulError> {
3434
let bytes = s.as_bytes();
3535
CStr::from_bytes_with_nul(bytes)?;
36-
Ok(unsafe { Self::from_bytes_with_nul_unchecked(bytes) })
36+
Ok(unsafe { Self::from_utf8_with_nul_unchecked(bytes) })
3737
}
3838
// rustdoc-stripper-ignore-next
3939
/// Unsafely creates a GLib string wrapper from a byte slice.
@@ -42,7 +42,7 @@ impl GStr {
4242
/// sanity checks. The provided slice **must** be valid UTF-8, nul-terminated and not contain
4343
/// any interior nul bytes.
4444
#[inline]
45-
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &Self {
45+
pub const unsafe fn from_utf8_with_nul_unchecked(bytes: &[u8]) -> &Self {
4646
debug_assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0);
4747
mem::transmute(bytes)
4848
}
@@ -53,7 +53,7 @@ impl GStr {
5353
#[inline]
5454
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a Self {
5555
let cstr = CStr::from_ptr(ptr);
56-
Self::from_bytes_with_nul_unchecked(cstr.to_bytes_with_nul())
56+
Self::from_utf8_with_nul_unchecked(cstr.to_bytes_with_nul())
5757
}
5858
// rustdoc-stripper-ignore-next
5959
/// Converts this GLib string to a byte slice containing the trailing 0 byte.
@@ -126,7 +126,7 @@ impl GStr {
126126
#[macro_export]
127127
macro_rules! gstr {
128128
($s:literal) => {
129-
unsafe { $crate::GStr::from_bytes_with_nul_unchecked($crate::cstr_bytes!($s)) }
129+
unsafe { $crate::GStr::from_utf8_with_nul_unchecked($crate::cstr_bytes!($s)) }
130130
};
131131
}
132132

@@ -142,7 +142,7 @@ impl<'a> TryFrom<&'a CStr> for &'a GStr {
142142
#[inline]
143143
fn try_from(s: &'a CStr) -> Result<Self, Self::Error> {
144144
s.to_str()?;
145-
Ok(unsafe { GStr::from_bytes_with_nul_unchecked(s.to_bytes_with_nul()) })
145+
Ok(unsafe { GStr::from_utf8_with_nul_unchecked(s.to_bytes_with_nul()) })
146146
}
147147
}
148148

@@ -279,7 +279,7 @@ unsafe impl<'a> crate::value::FromValue<'a> for &'a GStr {
279279
let ptr = gobject_ffi::g_value_get_string(value.to_glib_none().0);
280280
let cstr = CStr::from_ptr(ptr);
281281
assert!(cstr.to_str().is_ok());
282-
GStr::from_bytes_with_nul_unchecked(cstr.to_bytes_with_nul())
282+
GStr::from_utf8_with_nul_unchecked(cstr.to_bytes_with_nul())
283283
}
284284
}
285285

@@ -397,7 +397,7 @@ impl GString {
397397
slice::from_raw_parts(ptr.as_ptr() as *const _, len + 1)
398398
},
399399
};
400-
unsafe { GStr::from_bytes_with_nul_unchecked(bytes) }
400+
unsafe { GStr::from_utf8_with_nul_unchecked(bytes) }
401401
}
402402

403403
// rustdoc-stripper-ignore-next
@@ -435,7 +435,7 @@ impl GString {
435435

436436
impl Default for GString {
437437
fn default() -> Self {
438-
unsafe { GStr::from_bytes_with_nul_unchecked(b"\0") }.to_owned()
438+
unsafe { GStr::from_utf8_with_nul_unchecked(b"\0") }.to_owned()
439439
}
440440
}
441441

0 commit comments

Comments
 (0)