about summary refs log tree commit diff
path: root/library/core/src/array
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2022-10-23 19:17:41 +0200
committerThe 8472 <git@infinite-source.de>2022-11-07 21:44:25 +0100
commiteb3f001d3739e5e9f35e1a4b4e600889cf9980c6 (patch)
tree989ea209d1d82914596f3594669aded0038532ce /library/core/src/array
parentb00666ed09f186d9891be463355d6f8c984dcd9e (diff)
downloadrust-eb3f001d3739e5e9f35e1a4b4e600889cf9980c6.tar.gz
rust-eb3f001d3739e5e9f35e1a4b4e600889cf9980c6.zip
make the array initialization guard available to other modules
Diffstat (limited to 'library/core/src/array')
-rw-r--r--library/core/src/array/mod.rs36
1 files changed, 18 insertions, 18 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs
index eae0e1c7618..24e5d0fba21 100644
--- a/library/core/src/array/mod.rs
+++ b/library/core/src/array/mod.rs
@@ -865,24 +865,6 @@ where
         return Ok(Try::from_output(unsafe { mem::zeroed() }));
     }
 
-    struct Guard<'a, T, const N: usize> {
-        array_mut: &'a mut [MaybeUninit<T>; N],
-        initialized: usize,
-    }
-
-    impl<T, const N: usize> Drop for Guard<'_, T, N> {
-        fn drop(&mut self) {
-            debug_assert!(self.initialized <= N);
-
-            // SAFETY: this slice will contain only initialized objects.
-            unsafe {
-                crate::ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(
-                    &mut self.array_mut.get_unchecked_mut(..self.initialized),
-                ));
-            }
-        }
-    }
-
     let mut array = MaybeUninit::uninit_array::<N>();
     let mut guard = Guard { array_mut: &mut array, initialized: 0 };
 
@@ -920,6 +902,24 @@ where
     Ok(Try::from_output(output))
 }
 
+pub(crate) struct Guard<'a, T, const N: usize> {
+    pub array_mut: &'a mut [MaybeUninit<T>; N],
+    pub initialized: usize,
+}
+
+impl<T, const N: usize> Drop for Guard<'_, T, N> {
+    fn drop(&mut self) {
+        debug_assert!(self.initialized <= N);
+
+        // SAFETY: this slice will contain only initialized objects.
+        unsafe {
+            crate::ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(
+                &mut self.array_mut.get_unchecked_mut(..self.initialized),
+            ));
+        }
+    }
+}
+
 /// Returns the next chunk of `N` items from the iterator or errors with an
 /// iterator over the remainder. Used for `Iterator::next_chunk`.
 #[inline]