diff --git a/src/sealed.rs b/src/sealed.rs index 2efb07f2..53692319 100644 --- a/src/sealed.rs +++ b/src/sealed.rs @@ -52,6 +52,12 @@ pub(crate) const fn smaller_than() { Assert::::LESS; } +#[allow(dead_code)] +#[allow(path_statements)] +pub(crate) const fn greater_than_eq_0() { + Assert::::GREATER_EQ; +} + #[allow(dead_code)] #[allow(path_statements)] pub(crate) const fn greater_than_0() { diff --git a/src/vec.rs b/src/vec.rs index 51b4d50c..d458ea45 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -56,8 +56,8 @@ impl Vec { /// ``` /// `Vec` `const` constructor; wrap the returned value in [`Vec`](../struct.Vec.html) pub const fn new() -> Self { - // Const assert N > 0 - crate::sealed::greater_than_0::(); + // Const assert N >= 0 + crate::sealed::greater_than_eq_0::(); Self { buffer: [Self::INIT; N], @@ -1233,4 +1233,23 @@ mod tests { assert!(!v.ends_with(b"ba")); assert!(!v.ends_with(b"a")); } + + #[test] + fn zero_capacity() { + let mut v: Vec = Vec::new(); + // Validate capacity + assert_eq!(v.capacity(), 0); + + // Make sure there is no capacity + assert!(v.push(1).is_err()); + + // Validate length + assert_eq!(v.len(), 0); + + // Validate pop + assert_eq!(v.pop(), None); + + // Validate slice + assert_eq!(v.as_slice(), &[]); + } }