copy_stack_vec/vec/array/
new.rs

1// This file is part of copy-stack-vec.
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4// Crate imports
5use crate::vec::CopyStackVec;
6
7impl<T: Copy + Default, const N: usize> CopyStackVec<T, N> {
8    /// Constructs an empty vector with all elements initialized to `Default::default()`.
9    #[inline]
10    pub fn new() -> Self {
11        Self::default()
12    }
13}
14
15impl<T: Copy, const N: usize> CopyStackVec<T, N> {
16    /// Constructs an empty vector with the backing buffer filled with `fill`.
17    ///
18    /// Note: the initial **length** is `0`. The filled values become visible
19    /// only as you push/resize.
20    #[inline]
21    pub const fn new_with(fill: T) -> Self {
22        Self {
23            buf: [fill; N],
24            len: 0,
25        }
26    }
27}