@@ -433,6 +433,12 @@ impl GString {
433
433
}
434
434
}
435
435
436
+ impl Default for GString {
437
+ fn default ( ) -> Self {
438
+ unsafe { GStr :: from_bytes_with_nul_unchecked ( b"\0 " ) } . to_owned ( )
439
+ }
440
+ }
441
+
436
442
impl Clone for GString {
437
443
fn clone ( & self ) -> GString {
438
444
self . as_gstr ( ) . to_owned ( )
@@ -931,7 +937,7 @@ impl<'a> ToGlibPtr<'a, *mut i8> for GString {
931
937
impl < ' a > FromGlibContainer < * const c_char , * const i8 > for GString {
932
938
unsafe fn from_glib_none_num ( ptr : * const i8 , num : usize ) -> Self {
933
939
if num == 0 || ptr. is_null ( ) {
934
- return Self :: try_from ( "" ) . unwrap ( ) ;
940
+ return Self :: default ( ) ;
935
941
}
936
942
let slice = slice:: from_raw_parts ( ptr as * const u8 , num) ;
937
943
// Also check if it's valid UTF-8
@@ -940,7 +946,7 @@ impl<'a> FromGlibContainer<*const c_char, *const i8> for GString {
940
946
941
947
unsafe fn from_glib_container_num ( ptr : * const i8 , num : usize ) -> Self {
942
948
if num == 0 || ptr. is_null ( ) {
943
- return Self :: try_from ( "" ) . unwrap ( ) ;
949
+ return Self :: default ( ) ;
944
950
}
945
951
946
952
// Check if it's valid UTF-8
@@ -955,7 +961,7 @@ impl<'a> FromGlibContainer<*const c_char, *const i8> for GString {
955
961
956
962
unsafe fn from_glib_full_num ( ptr : * const i8 , num : usize ) -> Self {
957
963
if num == 0 || ptr. is_null ( ) {
958
- return Self :: try_from ( "" ) . unwrap ( ) ;
964
+ return Self :: default ( ) ;
959
965
}
960
966
961
967
// Check if it's valid UTF-8
0 commit comments