@@ -420,15 +420,17 @@ macro_rules! glib_boxed_wrapper {
420
420
421
421
( @memory_manager_impl $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty, @copy $copy_arg: ident $copy_expr: expr, @free $free_arg: ident $free_expr: expr) => {
422
422
#[ doc( hidden) ]
423
- impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: boxed:: BoxedMemoryManager <$ffi_name> for $name $( <$( $generic) ,+>) ? {
423
+ impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: boxed:: BoxedMemoryManager for $name $( <$( $generic) ,+>) ? {
424
+ type Target = $ffi_name;
425
+
424
426
#[ inline]
425
- unsafe fn copy( $copy_arg: * const $ffi_name ) -> * mut $ffi_name {
427
+ unsafe fn copy( $copy_arg: * const Self :: Target ) -> * mut Self :: Target {
426
428
$copy_expr
427
429
}
428
430
429
431
#[ inline]
430
432
#[ allow( clippy:: no_effect) ]
431
- unsafe fn free( $free_arg: * mut $ffi_name ) {
433
+ unsafe fn free( $free_arg: * mut Self :: Target ) {
432
434
$free_expr;
433
435
}
434
436
}
@@ -437,21 +439,23 @@ macro_rules! glib_boxed_wrapper {
437
439
438
440
// The safety docs really belong in the wrapper!() macro for Boxed<T>
439
441
/// Memory management functions for a boxed type.
440
- pub trait BoxedMemoryManager < T > : ' static {
442
+ pub trait BoxedMemoryManager : ' static {
443
+ type Target ;
444
+
441
445
/// Makes a copy.
442
- unsafe fn copy ( ptr : * const T ) -> * mut T ;
446
+ unsafe fn copy ( ptr : * const Self :: Target ) -> * mut Self :: Target ;
443
447
/// Frees the object.
444
- unsafe fn free ( ptr : * mut T ) ;
448
+ unsafe fn free ( ptr : * mut Self :: Target ) ;
445
449
}
446
450
447
451
/// Encapsulates memory management logic for boxed types.
448
452
#[ repr( transparent) ]
449
- pub struct Boxed < T : ' static , MM : BoxedMemoryManager < T > > {
453
+ pub struct Boxed < T : ' static , MM : BoxedMemoryManager < Target = T > > {
450
454
inner : ptr:: NonNull < T > ,
451
455
_dummy : PhantomData < * mut MM > ,
452
456
}
453
457
454
- impl < ' a , T : ' static , MM : BoxedMemoryManager < T > > ToGlibPtr < ' a , * const T > for Boxed < T , MM > {
458
+ impl < ' a , T : ' static , MM : BoxedMemoryManager < Target = T > > ToGlibPtr < ' a , * const T > for Boxed < T , MM > {
455
459
type Storage = PhantomData < & ' a Self > ;
456
460
457
461
#[ inline]
@@ -467,7 +471,7 @@ impl<'a, T: 'static, MM: BoxedMemoryManager<T>> ToGlibPtr<'a, *const T> for Boxe
467
471
}
468
472
}
469
473
470
- impl < ' a , T : ' static , MM : BoxedMemoryManager < T > > ToGlibPtrMut < ' a , * mut T > for Boxed < T , MM > {
474
+ impl < ' a , T : ' static , MM : BoxedMemoryManager < Target = T > > ToGlibPtrMut < ' a , * mut T > for Boxed < T , MM > {
471
475
type Storage = PhantomData < & ' a mut Self > ;
472
476
473
477
#[ inline]
@@ -477,7 +481,7 @@ impl<'a, T: 'static, MM: BoxedMemoryManager<T>> ToGlibPtrMut<'a, *mut T> for Box
477
481
}
478
482
}
479
483
480
- impl < T : ' static , MM : BoxedMemoryManager < T > > FromGlibPtrNone < * mut T > for Boxed < T , MM > {
484
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > FromGlibPtrNone < * mut T > for Boxed < T , MM > {
481
485
#[ inline]
482
486
unsafe fn from_glib_none ( ptr : * mut T ) -> Self {
483
487
debug_assert ! ( !ptr. is_null( ) ) ;
@@ -486,7 +490,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> FromGlibPtrNone<*mut T> for Boxed<T,
486
490
}
487
491
}
488
492
489
- impl < T : ' static , MM : BoxedMemoryManager < T > > FromGlibPtrNone < * const T > for Boxed < T , MM > {
493
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > FromGlibPtrNone < * const T > for Boxed < T , MM > {
490
494
#[ inline]
491
495
unsafe fn from_glib_none ( ptr : * const T ) -> Self {
492
496
debug_assert ! ( !ptr. is_null( ) ) ;
@@ -495,7 +499,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> FromGlibPtrNone<*const T> for Boxed<
495
499
}
496
500
}
497
501
498
- impl < T : ' static , MM : BoxedMemoryManager < T > > FromGlibPtrFull < * mut T > for Boxed < T , MM > {
502
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > FromGlibPtrFull < * mut T > for Boxed < T , MM > {
499
503
#[ inline]
500
504
unsafe fn from_glib_full ( ptr : * mut T ) -> Self {
501
505
debug_assert ! ( !ptr. is_null( ) ) ;
@@ -506,7 +510,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> FromGlibPtrFull<*mut T> for Boxed<T,
506
510
}
507
511
}
508
512
509
- impl < T : ' static , MM : BoxedMemoryManager < T > > FromGlibPtrFull < * const T > for Boxed < T , MM > {
513
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > FromGlibPtrFull < * const T > for Boxed < T , MM > {
510
514
#[ inline]
511
515
unsafe fn from_glib_full ( ptr : * const T ) -> Self {
512
516
debug_assert ! ( !ptr. is_null( ) ) ;
@@ -517,7 +521,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> FromGlibPtrFull<*const T> for Boxed<
517
521
}
518
522
}
519
523
520
- impl < T : ' static , MM : BoxedMemoryManager < T > > FromGlibPtrBorrow < * mut T > for Boxed < T , MM > {
524
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > FromGlibPtrBorrow < * mut T > for Boxed < T , MM > {
521
525
#[ inline]
522
526
unsafe fn from_glib_borrow ( ptr : * mut T ) -> Borrowed < Self > {
523
527
debug_assert ! ( !ptr. is_null( ) ) ;
@@ -528,7 +532,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> FromGlibPtrBorrow<*mut T> for Boxed<
528
532
}
529
533
}
530
534
531
- impl < T : ' static , MM : BoxedMemoryManager < T > > Drop for Boxed < T , MM > {
535
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > Drop for Boxed < T , MM > {
532
536
#[ inline]
533
537
fn drop ( & mut self ) {
534
538
unsafe {
@@ -537,36 +541,36 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> Drop for Boxed<T, MM> {
537
541
}
538
542
}
539
543
540
- impl < T : ' static , MM : BoxedMemoryManager < T > > fmt:: Debug for Boxed < T , MM > {
544
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > fmt:: Debug for Boxed < T , MM > {
541
545
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
542
546
f. debug_struct ( "Boxed" ) . field ( "inner" , & self . inner ) . finish ( )
543
547
}
544
548
}
545
549
546
- impl < T , MM : BoxedMemoryManager < T > > PartialOrd for Boxed < T , MM > {
550
+ impl < T , MM : BoxedMemoryManager < Target = T > > PartialOrd for Boxed < T , MM > {
547
551
#[ inline]
548
552
fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
549
553
self . to_glib_none ( ) . 0 . partial_cmp ( & other. to_glib_none ( ) . 0 )
550
554
}
551
555
}
552
556
553
- impl < T , MM : BoxedMemoryManager < T > > Ord for Boxed < T , MM > {
557
+ impl < T , MM : BoxedMemoryManager < Target = T > > Ord for Boxed < T , MM > {
554
558
#[ inline]
555
559
fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
556
560
self . to_glib_none ( ) . 0 . cmp ( & other. to_glib_none ( ) . 0 )
557
561
}
558
562
}
559
563
560
- impl < T , MM : BoxedMemoryManager < T > > PartialEq for Boxed < T , MM > {
564
+ impl < T , MM : BoxedMemoryManager < Target = T > > PartialEq for Boxed < T , MM > {
561
565
#[ inline]
562
566
fn eq ( & self , other : & Self ) -> bool {
563
567
self . to_glib_none ( ) . 0 == other. to_glib_none ( ) . 0
564
568
}
565
569
}
566
570
567
- impl < T , MM : BoxedMemoryManager < T > > Eq for Boxed < T , MM > { }
571
+ impl < T , MM : BoxedMemoryManager < Target = T > > Eq for Boxed < T , MM > { }
568
572
569
- impl < T , MM : BoxedMemoryManager < T > > Hash for Boxed < T , MM > {
573
+ impl < T , MM : BoxedMemoryManager < Target = T > > Hash for Boxed < T , MM > {
570
574
#[ inline]
571
575
fn hash < H > ( & self , state : & mut H )
572
576
where
@@ -576,14 +580,14 @@ impl<T, MM: BoxedMemoryManager<T>> Hash for Boxed<T, MM> {
576
580
}
577
581
}
578
582
579
- impl < T : ' static , MM : BoxedMemoryManager < T > > Clone for Boxed < T , MM > {
583
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > Clone for Boxed < T , MM > {
580
584
#[ inline]
581
585
fn clone ( & self ) -> Self {
582
586
unsafe { from_glib_none ( self . to_glib_none ( ) . 0 as * mut T ) }
583
587
}
584
588
}
585
589
586
- impl < T : ' static , MM : BoxedMemoryManager < T > > Deref for Boxed < T , MM > {
590
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > Deref for Boxed < T , MM > {
587
591
type Target = T ;
588
592
589
593
#[ inline]
@@ -595,7 +599,7 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> Deref for Boxed<T, MM> {
595
599
}
596
600
}
597
601
598
- impl < T : ' static , MM : BoxedMemoryManager < T > > DerefMut for Boxed < T , MM > {
602
+ impl < T : ' static , MM : BoxedMemoryManager < Target = T > > DerefMut for Boxed < T , MM > {
599
603
#[ inline]
600
604
fn deref_mut ( & mut self ) -> & mut T {
601
605
unsafe {
0 commit comments