copy_stack_vec/vec/array/into_array.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::{error::Error, vec::CopyStackVec};
6
7impl<T: Copy, const N: usize> CopyStackVec<T, N> {
8 /// Converts to `[T; N]` when **full** (`len == N`), otherwise returns [`Error::InvalidLen`].
9 #[inline]
10 pub fn try_into_array(self) -> Result<[T; N], Error> {
11 if self.len == N {
12 Ok(self.buf)
13 } else {
14 Err(Error::InvalidLen)
15 }
16 }
17}