File tree 2 files changed +18
-0
lines changed
godot-core/src/builtin/string
itest/rust/src/builtin_tests/string
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,22 @@ impl From<&str> for GString {
225
225
}
226
226
}
227
227
228
+ impl From < & [ char ] > for GString {
229
+ fn from ( chars : & [ char ] ) -> Self {
230
+ // SAFETY: `char` is by definition a valid Unicode scalar value.
231
+ unsafe {
232
+ Self :: new_with_string_uninit ( |string_ptr| {
233
+ let ctor = interface_fn ! ( string_new_with_utf32_chars_and_len) ;
234
+ ctor (
235
+ string_ptr,
236
+ chars. as_ptr ( ) as * const sys:: char32_t ,
237
+ chars. len ( ) as i64 ,
238
+ ) ;
239
+ } )
240
+ }
241
+ }
242
+ }
243
+
228
244
impl From < String > for GString {
229
245
fn from ( value : String ) -> Self {
230
246
value. as_str ( ) . into ( )
Original file line number Diff line number Diff line change @@ -69,12 +69,14 @@ fn string_chars() {
69
69
// Empty tests regression from #228: Null pointer passed to slice::from_raw_parts().
70
70
let string = GString :: new ( ) ;
71
71
assert_eq ! ( string. chars( ) , & [ ] ) ;
72
+ assert_eq ! ( string, GString :: from( [ ] . as_slice( ) ) ) ;
72
73
73
74
let string = String :: from ( "some_string" ) ;
74
75
let string_chars: Vec < char > = string. chars ( ) . collect ( ) ;
75
76
let gstring = GString :: from ( string) ;
76
77
77
78
assert_eq ! ( string_chars, gstring. chars( ) . to_vec( ) ) ;
79
+ assert_eq ! ( gstring, GString :: from( string_chars. as_slice( ) ) ) ;
78
80
}
79
81
80
82
#[ itest]
You can’t perform that action at this time.
0 commit comments