@@ -6,6 +6,7 @@ use core::clone::CloneToUninit;
6
6
use core:: marker:: PhantomData ;
7
7
#[ cfg( not( no_global_oom_handling) ) ]
8
8
use core:: mem;
9
+ use core:: mem:: MaybeUninit ;
9
10
use core:: ptr:: NonNull ;
10
11
11
12
use crate :: raw_rc:: RefCounter ;
@@ -476,3 +477,69 @@ impl<T, A> RawRc<T, A> {
476
477
}
477
478
}
478
479
}
480
+
481
+ impl < T , A > RawRc < MaybeUninit < T > , A > {
482
+ pub ( crate ) fn try_new_uninit ( ) -> Result < Self , AllocError >
483
+ where
484
+ A : Allocator + Default ,
485
+ {
486
+ RawWeak :: try_new_uninit :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
487
+ }
488
+
489
+ pub ( crate ) fn try_new_uninit_in ( alloc : A ) -> Result < Self , AllocError >
490
+ where
491
+ A : Allocator ,
492
+ {
493
+ RawWeak :: try_new_uninit_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
494
+ }
495
+
496
+ pub ( crate ) fn try_new_zeroed ( ) -> Result < Self , AllocError >
497
+ where
498
+ A : Allocator + Default ,
499
+ {
500
+ RawWeak :: try_new_zeroed :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
501
+ }
502
+
503
+ pub ( crate ) fn try_new_zeroed_in ( alloc : A ) -> Result < Self , AllocError >
504
+ where
505
+ A : Allocator ,
506
+ {
507
+ RawWeak :: try_new_zeroed_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
508
+ }
509
+
510
+ #[ cfg( not( no_global_oom_handling) ) ]
511
+ pub ( crate ) fn new_uninit ( ) -> Self
512
+ where
513
+ A : Allocator + Default ,
514
+ {
515
+ unsafe { Self :: from_weak ( RawWeak :: new_uninit :: < 1 > ( ) ) }
516
+ }
517
+
518
+ #[ cfg( not( no_global_oom_handling) ) ]
519
+ pub ( crate ) fn new_uninit_in ( alloc : A ) -> Self
520
+ where
521
+ A : Allocator ,
522
+ {
523
+ unsafe { Self :: from_weak ( RawWeak :: new_uninit_in :: < 1 > ( alloc) ) }
524
+ }
525
+
526
+ #[ cfg( not( no_global_oom_handling) ) ]
527
+ pub ( crate ) fn new_zeroed ( ) -> Self
528
+ where
529
+ A : Allocator + Default ,
530
+ {
531
+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed :: < 1 > ( ) ) }
532
+ }
533
+
534
+ #[ cfg( not( no_global_oom_handling) ) ]
535
+ pub ( crate ) fn new_zeroed_in ( alloc : A ) -> Self
536
+ where
537
+ A : Allocator ,
538
+ {
539
+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed_in :: < 1 > ( alloc) ) }
540
+ }
541
+
542
+ pub ( crate ) unsafe fn assume_init ( self ) -> RawRc < T , A > {
543
+ unsafe { self . cast ( ) }
544
+ }
545
+ }
0 commit comments