]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc/raw_vec.rs
Make Vec::new const
[rust.git] / src / liballoc / raw_vec.rs
index 7ef0a27fc7258876768fb3abfaac3396e9ff8da4..dc8ad9ee06169279fafa461a96769a32593f04c7 100644 (file)
@@ -68,6 +68,16 @@ pub fn new_in(a: A) -> Self {
         }
     }
 
+    /// Like `empty` but parametrized over the choice of allocator for the returned `RawVec`.
+    pub const fn empty_in(a: A) -> Self {
+        // Unique::empty() doubles as "unallocated" and "zero-sized allocation"
+        RawVec {
+            ptr: Unique::empty(),
+            cap: 0,
+            a,
+        }
+    }
+
     /// Like `with_capacity` but parameterized over the choice of
     /// allocator for the returned RawVec.
     #[inline]
@@ -124,6 +134,12 @@ pub fn new() -> Self {
         Self::new_in(Global)
     }
 
+    /// Create a `RawVec` with capcity 0 (on the system heap), regardless of `T`, without
+    /// allocating.
+    pub fn empty() -> Self {
+        Self::empty_in(Global)
+    }
+
     /// Creates a RawVec (on the system heap) with exactly the
     /// capacity and alignment requirements for a `[T; cap]`. This is
     /// equivalent to calling RawVec::new when `cap` is 0 or T is