@@ -5,9 +5,9 @@ use core::clone::CloneToUninit;
55#[ cfg( not( no_global_oom_handling) ) ]
66use core:: convert;
77use core:: marker:: PhantomData ;
8- use core:: mem:: DropGuard ;
98#[ cfg( not( no_global_oom_handling) ) ]
10- use core:: mem:: { self , MaybeUninit , SizedTypeProperties } ;
9+ use core:: mem:: { self , SizedTypeProperties } ;
10+ use core:: mem:: { DropGuard , MaybeUninit } ;
1111#[ cfg( not( no_global_oom_handling) ) ]
1212use core:: ops:: { DerefMut , Residual , Try } ;
1313#[ cfg( not( no_global_oom_handling) ) ]
@@ -454,7 +454,7 @@ impl<T, A> RawRc<T, A> {
454454 unsafe {
455455 allocation. get_mut_unchecked ( ) . write ( mapped_value) ;
456456
457- allocation. cast ( )
457+ allocation. assume_init ( )
458458 }
459459 } else {
460460 // Destruct `self` if `f` panics or returns a failure value.
@@ -530,6 +530,72 @@ impl<T, A> RawRc<T, A> {
530530 }
531531}
532532
533+ impl < T , A > RawRc < MaybeUninit < T > , A > {
534+ pub ( crate ) fn try_new_uninit ( ) -> Result < Self , AllocError >
535+ where
536+ A : Allocator + Default ,
537+ {
538+ RawWeak :: try_new_uninit :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
539+ }
540+
541+ pub ( crate ) fn try_new_uninit_in ( alloc : A ) -> Result < Self , AllocError >
542+ where
543+ A : Allocator ,
544+ {
545+ RawWeak :: try_new_uninit_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
546+ }
547+
548+ pub ( crate ) fn try_new_zeroed ( ) -> Result < Self , AllocError >
549+ where
550+ A : Allocator + Default ,
551+ {
552+ RawWeak :: try_new_zeroed :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
553+ }
554+
555+ pub ( crate ) fn try_new_zeroed_in ( alloc : A ) -> Result < Self , AllocError >
556+ where
557+ A : Allocator ,
558+ {
559+ RawWeak :: try_new_zeroed_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
560+ }
561+
562+ #[ cfg( not( no_global_oom_handling) ) ]
563+ pub ( crate ) fn new_uninit ( ) -> Self
564+ where
565+ A : Allocator + Default ,
566+ {
567+ unsafe { Self :: from_weak ( RawWeak :: new_uninit :: < 1 > ( ) ) }
568+ }
569+
570+ #[ cfg( not( no_global_oom_handling) ) ]
571+ pub ( crate ) fn new_uninit_in ( alloc : A ) -> Self
572+ where
573+ A : Allocator ,
574+ {
575+ unsafe { Self :: from_weak ( RawWeak :: new_uninit_in :: < 1 > ( alloc) ) }
576+ }
577+
578+ #[ cfg( not( no_global_oom_handling) ) ]
579+ pub ( crate ) fn new_zeroed ( ) -> Self
580+ where
581+ A : Allocator + Default ,
582+ {
583+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed :: < 1 > ( ) ) }
584+ }
585+
586+ #[ cfg( not( no_global_oom_handling) ) ]
587+ pub ( crate ) fn new_zeroed_in ( alloc : A ) -> Self
588+ where
589+ A : Allocator ,
590+ {
591+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed_in :: < 1 > ( alloc) ) }
592+ }
593+
594+ pub ( crate ) unsafe fn assume_init ( self ) -> RawRc < T , A > {
595+ unsafe { self . cast ( ) }
596+ }
597+ }
598+
533599/// Decrements strong reference count in a reference-counted allocation with a value object that is
534600/// pointed to by `value_ptr`.
535601#[ inline]
0 commit comments