Skip to content

Commit

Permalink
const fn new_with_len<const LEN: usize>() to heapless::Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce0203 committed May 19, 2024
1 parent 07c072c commit 899484f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,27 @@ impl<T, const N: usize> Vec<T, N> {
}
}

/// Constructs a new, empty vector with a fixed capacity of `N` with 'LEN'
///
/// # Examples
///
/// ```
/// use heapless::Vec;
///
/// // allocate the vector on the stack
/// let mut x: Vec<u8, 16> = Vec::new_len(4);
///
/// // allocate the vector in a static variable
/// static mut X: Vec<u8, 16> = Vec::new_len(4);
/// ```
pub const fn new_with_len<const LEN: usize>() -> Self {
crate::sealed::smaller_than::<LEN, N>();
Self {
len: LEN,
buffer: Self::INIT,
}
}

/// Constructs a new vector with a fixed capacity of `N` and fills it
/// with the provided slice.
///
Expand Down

0 comments on commit 899484f

Please sign in to comment.