| Crates.io | oxc_index |
| lib.rs | oxc_index |
| version | 4.1.0 |
| created_at | 2023-07-06 06:45:31.01781+00 |
| updated_at | 2025-10-04 04:46:58.22573+00 |
| description | Newtype-style helpers for `Vec` and `usize`. |
| homepage | |
| repository | https://github.com/oxc-project/oxc-index-vec |
| max_upload_size | |
| id | 909626 |
| size | 109,476 |
Forked version of index_vec.
This crate provides several optional features:
rayon - Enables parallel iteration support via Rayonserde - Enables serialization/deserialization support via Serdenonmax - Enables define_nonmax_u32_index_type! macro for memory-efficient index types using NonMaxU32Add this to your Cargo.toml:
[dependencies]
oxc_index = "3.1"
# Enable optional features as needed:
# oxc_index = { version = "3.1", features = ["serde", "nonmax"] }
use oxc_index::{IndexVec, define_index_type};
define_index_type! {
pub struct MyIdx = u32;
}
let mut vec: IndexVec<MyIdx, &str> = IndexVec::new();
let idx = vec.push("hello");
assert_eq!(vec[idx], "hello");
nonmax feature)The define_nonmax_u32_index_type! macro creates index types backed by NonMaxU32,
which uses the niche optimization to store Option<MyIdx> in the same space as MyIdx:
use oxc_index::{IndexVec, define_nonmax_u32_index_type};
define_nonmax_u32_index_type! {
pub struct CompactIdx;
}
// Option<CompactIdx> is the same size as CompactIdx (4 bytes)
assert_eq!(
std::mem::size_of::<CompactIdx>(),
std::mem::size_of::<Option<CompactIdx>>()
);
let mut vec: IndexVec<CompactIdx, String> = IndexVec::new();
let idx = vec.push("world".to_string());
serde feature)All index types and IndexVec automatically support Serde serialization when the serde feature is enabled:
use oxc_index::{IndexVec, define_index_type};
use serde::{Serialize, Deserialize};
define_index_type! {
pub struct MyIdx = u32;
}
#[derive(Serialize, Deserialize)]
struct MyData {
items: IndexVec<MyIdx, String>,
}
Compared to the original index_vec:
rayon feature - Parallel iteration supportserde feature - Automatic serialization support using the crate's own serde dependencynonmax feature - Memory-efficient index types with define_nonmax_u32_index_type! macroconst fn where possible#[ast], #[estree(skip)], etc.