@@ -2,9 +2,9 @@ use core::alloc::{AllocError, Allocator};
22use core:: cell:: UnsafeCell ;
33use core:: clone:: CloneToUninit ;
44use core:: marker:: PhantomData ;
5- use core:: mem:: DropGuard ;
65#[ cfg( not( no_global_oom_handling) ) ]
7- use core:: mem:: { self , MaybeUninit , SizedTypeProperties } ;
6+ use core:: mem:: { self , SizedTypeProperties } ;
7+ use core:: mem:: { DropGuard , MaybeUninit } ;
88#[ cfg( not( no_global_oom_handling) ) ]
99use core:: ops:: { ControlFlow , DerefMut , Try } ;
1010#[ cfg( not( no_global_oom_handling) ) ]
@@ -459,7 +459,7 @@ impl<T, A> RawRc<T, A> {
459459 unsafe {
460460 allocation. get_mut_unchecked ( ) . write ( mapped_value) ;
461461
462- allocation. cast ( )
462+ allocation. assume_init ( )
463463 }
464464 } else {
465465 // Destruct `self` if `f` panics or returns a failure value.
@@ -557,6 +557,72 @@ impl<T, A> RawRc<T, A> {
557557 }
558558}
559559
560+ impl < T , A > RawRc < MaybeUninit < T > , A > {
561+ pub ( crate ) fn try_new_uninit_in ( alloc : A ) -> Result < Self , AllocError >
562+ where
563+ A : Allocator ,
564+ {
565+ RawWeak :: try_new_uninit_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
566+ }
567+
568+ pub ( crate ) fn try_new_uninit ( ) -> Result < Self , AllocError >
569+ where
570+ A : Allocator + Default ,
571+ {
572+ RawWeak :: try_new_uninit :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
573+ }
574+
575+ pub ( crate ) fn try_new_zeroed_in ( alloc : A ) -> Result < Self , AllocError >
576+ where
577+ A : Allocator ,
578+ {
579+ RawWeak :: try_new_zeroed_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
580+ }
581+
582+ pub ( crate ) fn try_new_zeroed ( ) -> Result < Self , AllocError >
583+ where
584+ A : Allocator + Default ,
585+ {
586+ RawWeak :: try_new_zeroed :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
587+ }
588+
589+ #[ cfg( not( no_global_oom_handling) ) ]
590+ pub ( crate ) fn new_uninit_in ( alloc : A ) -> Self
591+ where
592+ A : Allocator ,
593+ {
594+ unsafe { Self :: from_weak ( RawWeak :: new_uninit_in :: < 1 > ( alloc) ) }
595+ }
596+
597+ #[ cfg( not( no_global_oom_handling) ) ]
598+ pub ( crate ) fn new_uninit ( ) -> Self
599+ where
600+ A : Allocator + Default ,
601+ {
602+ unsafe { Self :: from_weak ( RawWeak :: new_uninit :: < 1 > ( ) ) }
603+ }
604+
605+ #[ cfg( not( no_global_oom_handling) ) ]
606+ pub ( crate ) fn new_zeroed_in ( alloc : A ) -> Self
607+ where
608+ A : Allocator ,
609+ {
610+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed_in :: < 1 > ( alloc) ) }
611+ }
612+
613+ #[ cfg( not( no_global_oom_handling) ) ]
614+ pub ( crate ) fn new_zeroed ( ) -> Self
615+ where
616+ A : Allocator + Default ,
617+ {
618+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed :: < 1 > ( ) ) }
619+ }
620+
621+ pub ( crate ) unsafe fn assume_init ( self ) -> RawRc < T , A > {
622+ unsafe { self . cast ( ) }
623+ }
624+ }
625+
560626/// Decrements strong reference count in a reference-counted allocation with a value object that is
561627/// pointed to by `value_ptr`.
562628#[ inline]
0 commit comments