copy-stack-vec 0.1.0

A no_std, fixed-capacity, stack-allocated Copy vector for Copy types, with no unsafe code by default.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// This file is part of copy-stack-vec.
// SPDX-License-Identifier: MIT OR Apache-2.0

// Crate imports
use crate::{error::Error, vec::CopyStackVec};

impl<T: Copy, const N: usize> CopyStackVec<T, N> {
    /// Converts to `[T; N]` when **full** (`len == N`), otherwise returns [`Error::InvalidLen`].
    #[inline]
    pub fn try_into_array(self) -> Result<[T; N], Error> {
        if self.len == N {
            Ok(self.buf)
        } else {
            Err(Error::InvalidLen)
        }
    }
}