@@ -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 } ;
1010use core:: ptr:: NonNull ;
@@ -449,7 +449,7 @@ impl<T, A> RawRc<T, A> {
449449 unsafe {
450450 allocation. get_mut_unchecked ( ) . write ( mapped_value) ;
451451
452- allocation. cast ( )
452+ allocation. assume_init ( )
453453 }
454454 } else {
455455 // Destruct `self` if `f` panics or returns a failure value.
@@ -547,6 +547,72 @@ impl<T, A> RawRc<T, A> {
547547 }
548548}
549549
550+ impl < T , A > RawRc < MaybeUninit < T > , A > {
551+ pub ( crate ) fn try_new_uninit_in ( alloc : A ) -> Result < Self , AllocError >
552+ where
553+ A : Allocator ,
554+ {
555+ RawWeak :: try_new_uninit_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
556+ }
557+
558+ pub ( crate ) fn try_new_uninit ( ) -> Result < Self , AllocError >
559+ where
560+ A : Allocator + Default ,
561+ {
562+ RawWeak :: try_new_uninit :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
563+ }
564+
565+ pub ( crate ) fn try_new_zeroed_in ( alloc : A ) -> Result < Self , AllocError >
566+ where
567+ A : Allocator ,
568+ {
569+ RawWeak :: try_new_zeroed_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
570+ }
571+
572+ pub ( crate ) fn try_new_zeroed ( ) -> Result < Self , AllocError >
573+ where
574+ A : Allocator + Default ,
575+ {
576+ RawWeak :: try_new_zeroed :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
577+ }
578+
579+ #[ cfg( not( no_global_oom_handling) ) ]
580+ pub ( crate ) fn new_uninit_in ( alloc : A ) -> Self
581+ where
582+ A : Allocator ,
583+ {
584+ unsafe { Self :: from_weak ( RawWeak :: new_uninit_in :: < 1 > ( alloc) ) }
585+ }
586+
587+ #[ cfg( not( no_global_oom_handling) ) ]
588+ pub ( crate ) fn new_uninit ( ) -> Self
589+ where
590+ A : Allocator + Default ,
591+ {
592+ unsafe { Self :: from_weak ( RawWeak :: new_uninit :: < 1 > ( ) ) }
593+ }
594+
595+ #[ cfg( not( no_global_oom_handling) ) ]
596+ pub ( crate ) fn new_zeroed_in ( alloc : A ) -> Self
597+ where
598+ A : Allocator ,
599+ {
600+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed_in :: < 1 > ( alloc) ) }
601+ }
602+
603+ #[ cfg( not( no_global_oom_handling) ) ]
604+ pub ( crate ) fn new_zeroed ( ) -> Self
605+ where
606+ A : Allocator + Default ,
607+ {
608+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed :: < 1 > ( ) ) }
609+ }
610+
611+ pub ( crate ) unsafe fn assume_init ( self ) -> RawRc < T , A > {
612+ unsafe { self . cast ( ) }
613+ }
614+ }
615+
550616/// Decrements strong reference count in a reference-counted allocation with a value object that is
551617/// pointed to by `value_ptr`.
552618#[ inline]
0 commit comments