@@ -431,25 +431,13 @@ macro_rules! glib_boxed_inline_wrapper {
431
431
}
432
432
433
433
#[ doc( hidden) ]
434
- impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibContainerAsVec <* mut $ffi_name, * mut $ffi_name> for $name $( <$( $generic) ,+>) ? {
435
- unsafe fn from_glib_none_num_as_vec( ptr: * mut $ffi_name, num: usize ) -> Vec <Self > {
436
- $crate:: translate:: FromGlibContainerAsVec :: from_glib_none_num_as_vec( ptr as * const _, num)
437
- }
438
-
439
- unsafe fn from_glib_container_num_as_vec( ptr: * mut $ffi_name, num: usize ) -> Vec <Self > {
440
- $crate:: translate:: FromGlibContainerAsVec :: from_glib_container_num_as_vec( ptr as * const _, num)
441
- }
442
-
443
- unsafe fn from_glib_full_num_as_vec( ptr: * mut $ffi_name, num: usize ) -> Vec <Self > {
444
- $crate:: translate:: FromGlibContainerAsVec :: from_glib_full_num_as_vec( ptr as * const _, num)
445
- }
446
- }
447
-
448
- #[ doc( hidden) ]
449
- impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibContainerAsVec <* mut $ffi_name, * const $ffi_name> for $name $( <$( $generic) ,+>) ? {
450
- unsafe fn from_glib_none_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Vec <Self > {
451
- if num == 0 || ptr. is_null( ) {
452
- return Vec :: new( ) ;
434
+ impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: TryFromGlibContainerAsVec <* mut $ffi_name, * const $ffi_name> for $name $( <$( $generic) ,+>) ? {
435
+ unsafe fn try_from_glib_none_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Option <Vec <Self >> {
436
+ if ptr. is_null( ) {
437
+ return None ;
438
+ }
439
+ if num == 0 {
440
+ return Some ( Vec :: new( ) ) ;
453
441
}
454
442
455
443
let mut res = Vec :: <Self >:: with_capacity( num) ;
@@ -458,35 +446,71 @@ macro_rules! glib_boxed_inline_wrapper {
458
446
:: std:: ptr:: write( res_ptr. add( i) , $crate:: translate:: from_glib_none( ptr. add( i) ) ) ;
459
447
}
460
448
res. set_len( num) ;
461
- res
449
+ Some ( res)
462
450
}
463
451
464
- unsafe fn from_glib_container_num_as_vec ( ptr: * const $ffi_name, num: usize ) -> Vec <Self > {
465
- let res = $crate:: translate:: FromGlibContainerAsVec :: from_glib_none_num_as_vec ( ptr, num) ;
452
+ unsafe fn try_from_glib_container_num_as_vec ( ptr: * const $ffi_name, num: usize ) -> Option < Vec <Self > > {
453
+ let res = $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_none_num_as_vec ( ptr, num) ? ;
466
454
$crate:: ffi:: g_free( ptr as * mut _) ;
467
- res
455
+ Some ( res)
468
456
}
469
457
470
- unsafe fn from_glib_full_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Vec <Self > {
471
- if num == 0 || ptr. is_null( ) {
458
+ unsafe fn try_from_glib_full_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Option <Vec <Self >> {
459
+ if ptr. is_null( ) {
460
+ return None ;
461
+ }
462
+ if num == 0 {
472
463
$crate:: ffi:: g_free( ptr as * mut _) ;
473
- return Vec :: new( ) ;
464
+ return Some ( Vec :: new( ) ) ;
474
465
}
475
466
476
467
let mut res = Vec :: with_capacity( num) ;
477
468
let res_ptr = res. as_mut_ptr( ) ;
478
469
:: std:: ptr:: copy_nonoverlapping( ptr as * mut Self , res_ptr, num) ;
479
470
res. set_len( num) ;
480
471
$crate:: ffi:: g_free( ptr as * mut _) ;
481
- res
472
+ Some ( res)
482
473
}
483
474
}
484
475
485
476
#[ doc( hidden) ]
486
- impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibContainerAsVec <* mut $ffi_name, * mut * mut $ffi_name> for $name $( <$( $generic) ,+>) ? {
487
- unsafe fn from_glib_none_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Vec <Self > {
488
- if num == 0 || ptr. is_null( ) {
489
- return Vec :: new( ) ;
477
+ impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibContainerAsVec <* mut $ffi_name, * mut $ffi_name> for $name $( <$( $generic) ,+>) ? {
478
+ unsafe fn from_glib_none_num_as_vec( ptr: * mut $ffi_name, num: usize ) -> Vec <Self > {
479
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_none_num_as_vec( ptr as * const _, num) . unwrap_or_default( )
480
+ }
481
+
482
+ unsafe fn from_glib_container_num_as_vec( ptr: * mut $ffi_name, num: usize ) -> Vec <Self > {
483
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_container_num_as_vec( ptr as * const _, num) . unwrap_or_default( )
484
+ }
485
+
486
+ unsafe fn from_glib_full_num_as_vec( ptr: * mut $ffi_name, num: usize ) -> Vec <Self > {
487
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_full_num_as_vec( ptr as * const _, num) . unwrap_or_default( )
488
+ }
489
+ }
490
+
491
+ #[ doc( hidden) ]
492
+ impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibContainerAsVec <* mut $ffi_name, * const $ffi_name> for $name $( <$( $generic) ,+>) ? {
493
+ unsafe fn from_glib_none_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Vec <Self > {
494
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_none_num_as_vec( ptr, num) . unwrap_or_default( )
495
+ }
496
+
497
+ unsafe fn from_glib_container_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Vec <Self > {
498
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_container_num_as_vec( ptr, num) . unwrap_or_default( )
499
+ }
500
+
501
+ unsafe fn from_glib_full_num_as_vec( ptr: * const $ffi_name, num: usize ) -> Vec <Self > {
502
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_full_num_as_vec( ptr, num) . unwrap_or_default( )
503
+ }
504
+ }
505
+
506
+ #[ doc( hidden) ]
507
+ impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: TryFromGlibContainerAsVec <* mut $ffi_name, * mut * mut $ffi_name> for $name $( <$( $generic) ,+>) ? {
508
+ unsafe fn try_from_glib_none_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Option <Vec <Self >> {
509
+ if ptr. is_null( ) {
510
+ return None ;
511
+ }
512
+ if num == 0 {
513
+ return Some ( Vec :: new( ) ) ;
490
514
}
491
515
492
516
let mut res = Vec :: <Self >:: with_capacity( num) ;
@@ -495,19 +519,22 @@ macro_rules! glib_boxed_inline_wrapper {
495
519
:: std:: ptr:: write( res_ptr. add( i) , $crate:: translate:: from_glib_none( :: std:: ptr:: read( ptr. add( i) ) ) ) ;
496
520
}
497
521
res. set_len( num) ;
498
- res
522
+ Some ( res)
499
523
}
500
524
501
- unsafe fn from_glib_container_num_as_vec ( ptr: * mut * mut $ffi_name, num: usize ) -> Vec <Self > {
502
- let res = $crate:: translate:: FromGlibContainerAsVec :: from_glib_none_num_as_vec ( ptr, num) ;
525
+ unsafe fn try_from_glib_container_num_as_vec ( ptr: * mut * mut $ffi_name, num: usize ) -> Option < Vec <Self > > {
526
+ let res = $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_none_num_as_vec ( ptr, num) ? ;
503
527
$crate:: ffi:: g_free( ptr as * mut _) ;
504
- res
528
+ Some ( res)
505
529
}
506
530
507
- unsafe fn from_glib_full_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Vec <Self > {
508
- if num == 0 || ptr. is_null( ) {
531
+ unsafe fn try_from_glib_full_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Option <Vec <Self >> {
532
+ if ptr. is_null( ) {
533
+ return None ;
534
+ }
535
+ if num == 0 {
509
536
$crate:: ffi:: g_free( ptr as * mut _) ;
510
- return Vec :: new( ) ;
537
+ return Some ( Vec :: new( ) ) ;
511
538
}
512
539
513
540
let mut res = Vec :: <Self >:: with_capacity( num) ;
@@ -517,22 +544,37 @@ macro_rules! glib_boxed_inline_wrapper {
517
544
}
518
545
res. set_len( num) ;
519
546
$crate:: ffi:: g_free( ptr as * mut _) ;
520
- res
547
+ Some ( res)
548
+ }
549
+ }
550
+
551
+ #[ doc( hidden) ]
552
+ impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibContainerAsVec <* mut $ffi_name, * mut * mut $ffi_name> for $name $( <$( $generic) ,+>) ? {
553
+ unsafe fn from_glib_none_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Vec <Self > {
554
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_none_num_as_vec( ptr, num) . unwrap_or_default( )
555
+ }
556
+
557
+ unsafe fn from_glib_container_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Vec <Self > {
558
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_container_num_as_vec( ptr, num) . unwrap_or_default( )
559
+ }
560
+
561
+ unsafe fn from_glib_full_num_as_vec( ptr: * mut * mut $ffi_name, num: usize ) -> Vec <Self > {
562
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_full_num_as_vec( ptr, num) . unwrap_or_default( )
521
563
}
522
564
}
523
565
524
566
#[ doc( hidden) ]
525
567
impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: FromGlibPtrArrayContainerAsVec <* mut $ffi_name, * mut * mut $ffi_name> for $name $( <$( $generic) ,+>) ? {
526
568
unsafe fn from_glib_none_as_vec( ptr: * mut * mut $ffi_name) -> Vec <Self > {
527
- $crate:: translate:: FromGlibContainerAsVec :: from_glib_none_num_as_vec ( ptr, $crate:: translate:: c_ptr_array_len( ptr) )
569
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_none_num_as_vec ( ptr, $crate:: translate:: c_ptr_array_len( ptr) . unwrap_or ( 0 ) ) . unwrap_or_default ( )
528
570
}
529
571
530
572
unsafe fn from_glib_container_as_vec( ptr: * mut * mut $ffi_name) -> Vec <Self > {
531
- $crate:: translate:: FromGlibContainerAsVec :: from_glib_container_num_as_vec ( ptr, $crate:: translate:: c_ptr_array_len( ptr) )
573
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_container_num_as_vec ( ptr, $crate:: translate:: c_ptr_array_len( ptr) . unwrap_or ( 0 ) ) . unwrap_or_default ( )
532
574
}
533
575
534
576
unsafe fn from_glib_full_as_vec( ptr: * mut * mut $ffi_name) -> Vec <Self > {
535
- $crate:: translate:: FromGlibContainerAsVec :: from_glib_full_num_as_vec ( ptr, $crate:: translate:: c_ptr_array_len( ptr) )
577
+ $crate:: translate:: TryFromGlibContainerAsVec :: try_from_glib_full_num_as_vec ( ptr, $crate:: translate:: c_ptr_array_len( ptr) . unwrap_or ( 0 ) ) . unwrap_or_default ( )
536
578
}
537
579
}
538
580
#[ doc( hidden) ]
0 commit comments