DioxusLabs/dioxus · error

const vec index out of bounds

Error message

const vec index out of bounds

What it means

`ConstVec::at` panics when the requested index is >= the vec's length. Unlike `get`, which returns Option, `at` is an unchecked-style accessor for const contexts where the caller must guarantee the index is valid; firing means the caller indexed past the elements stored in the const vec.

Source

Thrown at packages/dioxus-const-vec/src/lib.rs:211

    /// assert_eq!(ONE.get(0), Some(&1));
    /// ```
    pub const fn get(&self, index: usize) -> Option<&T> {
        if index < self.len as usize {
            Some(unsafe { &*self.memory[index].as_ptr() })
        } else {
            None
        }
    }

    /// Get a copy of the value at the given index.
    ///
    /// This panics if `index` is out of bounds.
    pub const fn at(&self, index: usize) -> T
    where
        T: Copy,
    {
        if index >= self.len as usize {
            panic!("const vec index out of bounds");
        }
        unsafe { self.memory[index].assume_init() }
    }

    /// Get the length of the [`ConstVec`].
    ///
    /// # Example
    ///
    /// ```rust
    /// # use dioxus_const_vec::ConstVec;
    /// const ONE: ConstVec<u8> = {
    ///     let mut vec = ConstVec::new();
    ///     vec.push(1);
    ///     vec
    /// };
    /// assert_eq!(ONE.len(), 1);
    /// ```
    pub const fn len(&self) -> usize {

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Use an index smaller than the const vec length; check bounds before indexing.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/dioxus-const-vec/src/lib.rs:211 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/d3561ccef759a89c. Report an issue: GitHub.