File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,21 @@ impl<'a, const N: usize> From<[&'a str; N]> for StrV {
358
358
}
359
359
}
360
360
361
+ impl < ' a , const N : usize > From < [ & ' a GStr ; N ] > for StrV {
362
+ #[ inline]
363
+ fn from ( value : [ & ' a GStr ; N ] ) -> Self {
364
+ unsafe {
365
+ let mut s = Self :: with_capacity ( value. len ( ) ) ;
366
+ for ( i, item) in value. iter ( ) . enumerate ( ) {
367
+ * s. ptr . as_ptr ( ) . add ( i) = GString :: from ( * item) . into_glib_ptr ( ) ;
368
+ }
369
+ s. len = value. len ( ) ;
370
+ * s. ptr . as_ptr ( ) . add ( s. len ) = ptr:: null_mut ( ) ;
371
+ s
372
+ }
373
+ }
374
+ }
375
+
361
376
impl < ' a > From < & ' a [ & ' a str ] > for StrV {
362
377
#[ inline]
363
378
fn from ( value : & ' a [ & ' a str ] ) -> Self {
@@ -1398,6 +1413,20 @@ mod test {
1398
1413
}
1399
1414
}
1400
1415
1416
+ #[ test]
1417
+ fn test_from_slice ( ) {
1418
+ let items = [
1419
+ crate :: gstr!( "str1" ) ,
1420
+ crate :: gstr!( "str2" ) ,
1421
+ crate :: gstr!( "str3" ) ,
1422
+ ] ;
1423
+
1424
+ let slice1 = StrV :: from ( & items[ ..] ) ;
1425
+ let slice2 = StrV :: from ( items) ;
1426
+ assert_eq ! ( slice1. len( ) , 3 ) ;
1427
+ assert_eq ! ( slice1, slice2) ;
1428
+ }
1429
+
1401
1430
#[ test]
1402
1431
fn test_safe_api ( ) {
1403
1432
let items = [
You can’t perform that action at this time.
0 commit comments