@@ -149,6 +149,38 @@ pub fn zeroed_slice_box<T: Zeroable>(length: usize) -> Box<[T]> {
149
149
try_zeroed_slice_box ( length) . unwrap ( )
150
150
}
151
151
152
+ /// Allocates a `Arc<T>` with all contents being zeroed out.
153
+ #[ cfg( all( feature = "alloc_uninit" , target_has_atomic = "ptr" ) ) ]
154
+ pub fn zeroed_arc < T : Zeroable > ( ) -> Arc < T > {
155
+ let mut arc = Arc :: new_uninit ( ) ;
156
+ crate :: write_zeroes ( Arc :: get_mut ( & mut arc) . unwrap ( ) ) ; // unwrap never fails for a newly allocated Arc
157
+ unsafe { arc. assume_init ( ) }
158
+ }
159
+
160
+ /// Allocates a `Arc<[T]>` with all contents being zeroed out.
161
+ #[ cfg( all( feature = "alloc_uninit" , target_has_atomic = "ptr" ) ) ]
162
+ pub fn zeroed_arc_slice < T : Zeroable > ( length : usize ) -> Arc < [ T ] > {
163
+ let mut arc = Arc :: new_uninit_slice ( length) ;
164
+ crate :: fill_zeroes ( Arc :: get_mut ( & mut arc) . unwrap ( ) ) ; // unwrap never fails for a newly allocated Arc
165
+ unsafe { arc. assume_init ( ) }
166
+ }
167
+
168
+ /// Allocates a `Rc<T>` with all contents being zeroed out.
169
+ #[ cfg( feature = "alloc_uninit" ) ]
170
+ pub fn zeroed_rc < T : Zeroable > ( ) -> Rc < T > {
171
+ let mut rc = Rc :: new_uninit ( ) ;
172
+ crate :: write_zeroes ( Rc :: get_mut ( & mut rc) . unwrap ( ) ) ; // unwrap never fails for a newly allocated Rc
173
+ unsafe { rc. assume_init ( ) }
174
+ }
175
+
176
+ /// Allocates a `Rc<[T]>` with all contents being zeroed out.
177
+ #[ cfg( feature = "alloc_uninit" ) ]
178
+ pub fn zeroed_rc_slice < T : Zeroable > ( length : usize ) -> Rc < [ T ] > {
179
+ let mut rc = Rc :: new_uninit_slice ( length) ;
180
+ crate :: fill_zeroes ( Rc :: get_mut ( & mut rc) . unwrap ( ) ) ; // unwrap never fails for a newly allocated Rc
181
+ unsafe { rc. assume_init ( ) }
182
+ }
183
+
152
184
/// As [`try_cast_slice_box`], but unwraps for you.
153
185
#[ inline]
154
186
pub fn cast_slice_box < A : NoUninit , B : AnyBitPattern > (
0 commit comments