@@ -33,7 +33,7 @@ impl GStr {
33
33
pub fn from_str_with_nul ( s : & str ) -> Result < & Self , std:: ffi:: FromBytesWithNulError > {
34
34
let bytes = s. as_bytes ( ) ;
35
35
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) } )
37
37
}
38
38
// rustdoc-stripper-ignore-next
39
39
/// Unsafely creates a GLib string wrapper from a byte slice.
@@ -42,7 +42,7 @@ impl GStr {
42
42
/// sanity checks. The provided slice **must** be valid UTF-8, nul-terminated and not contain
43
43
/// any interior nul bytes.
44
44
#[ 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 {
46
46
debug_assert ! ( !bytes. is_empty( ) && bytes[ bytes. len( ) - 1 ] == 0 ) ;
47
47
mem:: transmute ( bytes)
48
48
}
@@ -53,7 +53,7 @@ impl GStr {
53
53
#[ inline]
54
54
pub unsafe fn from_ptr < ' a > ( ptr : * const c_char ) -> & ' a Self {
55
55
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 ( ) )
57
57
}
58
58
// rustdoc-stripper-ignore-next
59
59
/// Converts this GLib string to a byte slice containing the trailing 0 byte.
@@ -126,7 +126,7 @@ impl GStr {
126
126
#[ macro_export]
127
127
macro_rules! gstr {
128
128
( $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) ) }
130
130
} ;
131
131
}
132
132
@@ -142,7 +142,7 @@ impl<'a> TryFrom<&'a CStr> for &'a GStr {
142
142
#[ inline]
143
143
fn try_from ( s : & ' a CStr ) -> Result < Self , Self :: Error > {
144
144
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 ( ) ) } )
146
146
}
147
147
}
148
148
@@ -279,7 +279,7 @@ unsafe impl<'a> crate::value::FromValue<'a> for &'a GStr {
279
279
let ptr = gobject_ffi:: g_value_get_string ( value. to_glib_none ( ) . 0 ) ;
280
280
let cstr = CStr :: from_ptr ( ptr) ;
281
281
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 ( ) )
283
283
}
284
284
}
285
285
@@ -397,7 +397,7 @@ impl GString {
397
397
slice:: from_raw_parts ( ptr. as_ptr ( ) as * const _ , len + 1 )
398
398
} ,
399
399
} ;
400
- unsafe { GStr :: from_bytes_with_nul_unchecked ( bytes) }
400
+ unsafe { GStr :: from_utf8_with_nul_unchecked ( bytes) }
401
401
}
402
402
403
403
// rustdoc-stripper-ignore-next
@@ -435,7 +435,7 @@ impl GString {
435
435
436
436
impl Default for GString {
437
437
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 ( )
439
439
}
440
440
}
441
441
0 commit comments