@@ -3,9 +3,9 @@ use core::cell::UnsafeCell;
33#[ cfg( not( no_global_oom_handling) ) ]
44use core:: clone:: CloneToUninit ;
55use core:: marker:: PhantomData ;
6- use core:: mem:: DropGuard ;
76#[ cfg( not( no_global_oom_handling) ) ]
8- use core:: mem:: { self , MaybeUninit , SizedTypeProperties } ;
7+ use core:: mem:: { self , SizedTypeProperties } ;
8+ use core:: mem:: { DropGuard , MaybeUninit } ;
99#[ cfg( not( no_global_oom_handling) ) ]
1010use core:: ops:: { ControlFlow , DerefMut , Try } ;
1111#[ cfg( not( no_global_oom_handling) ) ]
@@ -451,7 +451,7 @@ impl<T, A> RawRc<T, A> {
451451 unsafe {
452452 allocation. get_mut_unchecked ( ) . write ( mapped_value) ;
453453
454- allocation. cast ( )
454+ allocation. assume_init ( )
455455 }
456456 } else {
457457 // Destruct `self` if `f` panics or returns a failure value.
@@ -527,6 +527,72 @@ impl<T, A> RawRc<T, A> {
527527 }
528528}
529529
530+ impl < T , A > RawRc < MaybeUninit < T > , A > {
531+ pub ( crate ) fn try_new_uninit ( ) -> Result < Self , AllocError >
532+ where
533+ A : Allocator + Default ,
534+ {
535+ RawWeak :: try_new_uninit :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
536+ }
537+
538+ pub ( crate ) fn try_new_uninit_in ( alloc : A ) -> Result < Self , AllocError >
539+ where
540+ A : Allocator ,
541+ {
542+ RawWeak :: try_new_uninit_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
543+ }
544+
545+ pub ( crate ) fn try_new_zeroed ( ) -> Result < Self , AllocError >
546+ where
547+ A : Allocator + Default ,
548+ {
549+ RawWeak :: try_new_zeroed :: < 1 > ( ) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
550+ }
551+
552+ pub ( crate ) fn try_new_zeroed_in ( alloc : A ) -> Result < Self , AllocError >
553+ where
554+ A : Allocator ,
555+ {
556+ RawWeak :: try_new_zeroed_in :: < 1 > ( alloc) . map ( |weak| unsafe { Self :: from_weak ( weak) } )
557+ }
558+
559+ #[ cfg( not( no_global_oom_handling) ) ]
560+ pub ( crate ) fn new_uninit ( ) -> Self
561+ where
562+ A : Allocator + Default ,
563+ {
564+ unsafe { Self :: from_weak ( RawWeak :: new_uninit :: < 1 > ( ) ) }
565+ }
566+
567+ #[ cfg( not( no_global_oom_handling) ) ]
568+ pub ( crate ) fn new_uninit_in ( alloc : A ) -> Self
569+ where
570+ A : Allocator ,
571+ {
572+ unsafe { Self :: from_weak ( RawWeak :: new_uninit_in :: < 1 > ( alloc) ) }
573+ }
574+
575+ #[ cfg( not( no_global_oom_handling) ) ]
576+ pub ( crate ) fn new_zeroed ( ) -> Self
577+ where
578+ A : Allocator + Default ,
579+ {
580+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed :: < 1 > ( ) ) }
581+ }
582+
583+ #[ cfg( not( no_global_oom_handling) ) ]
584+ pub ( crate ) fn new_zeroed_in ( alloc : A ) -> Self
585+ where
586+ A : Allocator ,
587+ {
588+ unsafe { Self :: from_weak ( RawWeak :: new_zeroed_in :: < 1 > ( alloc) ) }
589+ }
590+
591+ pub ( crate ) unsafe fn assume_init ( self ) -> RawRc < T , A > {
592+ unsafe { self . cast ( ) }
593+ }
594+ }
595+
530596/// Decrements strong reference count in a reference-counted allocation with a value object that is
531597/// pointed to by `value_ptr`.
532598#[ inline]
0 commit comments