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
// This file is part of copy-stack-vec.
// SPDX-License-Identifier: MIT OR Apache-2.0

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

impl<T: Copy, const N: usize> CopyStackVec<T, N> {
    /// Inserts `value` at `index`, shifting elements to the right.
    ///
    /// - Returns [`Error::OutOfBounds`] if `index > len`.
    /// - Returns [`Error::Full`] if at capacity.
    ///
    /// Uses `copy_within` for overlap-safe shifting.
    #[inline]
    pub fn insert(&mut self, index: usize, value: T) -> Result<(), Error> {
        if index > self.len {
            return Err(Error::OutOfBounds);
        }
        if self.len == N {
            return Err(Error::Full);
        }
        let len = self.len;

        // Shift right: [index..len) -> [index+1..len+1)
        self.buf.copy_within(index..len, index + 1);
        self.buf[index].write(value);

        self.len = len + 1;
        Ok(())
    }
}