Skip to content

Commit 6b47771

Browse files
committed
Add RawRc methods for MaybeUninit<T> values
1 parent 6cb537c commit 6b47771

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

library/alloc/src/raw_rc/raw_rc.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use core::clone::CloneToUninit;
66
use core::marker::PhantomData;
77
#[cfg(not(no_global_oom_handling))]
88
use core::mem;
9+
use core::mem::MaybeUninit;
910
use core::ptr::NonNull;
1011

1112
use crate::raw_rc::RefCounter;
@@ -476,3 +477,69 @@ impl<T, A> RawRc<T, A> {
476477
}
477478
}
478479
}
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

Comments
 (0)