indexmap
A hash table with consistent order and fast iteration.
This package has a good security score with no known vulnerabilities.
Community Reviews
Drop-in HashMap replacement with insertion order - just works
The ergonomics are excellent. Methods like `.swap_remove()`, `.shift_remove()`, and `.get_index()` expose the ordering capabilities naturally. Serde integration works seamlessly with the same derives you'd use on HashMap. Error messages are standard Rust quality since it leverages familiar patterns. The documentation is thorough with clear examples for order-specific operations.
Performance characteristics are well-documented and predictable. It's slightly slower than HashMap for some operations but faster for iteration, which is usually the tradeoff you want when choosing this crate. The type signatures work beautifully with IDE autocomplete, and migrating from HashMap requires almost zero code changes beyond the import statement.
Best for: Applications needing deterministic map iteration, JSON serialization with stable field order, or LRU-style caching with ordered removal.
Avoid if: You never iterate over map contents and need absolute maximum single-operation performance from a hash table.
Drop-in HashMap replacement with predictable ordering - just works
The documentation is straightforward with clear examples showing the ordering guarantees. Error messages are what you'd expect from standard collection types - nothing surprising or cryptic. The crate's simplicity means there's not much to go wrong: you get your HashMap operations plus index-based access and guaranteed insertion order. Performance is excellent for iteration, which is often the bottleneck in real applications.
Debugging is trivial because the behavior is so predictable. When I print an IndexMap, keys appear in insertion order every time, which makes logging and testing substantially easier than with HashMap's arbitrary ordering. The .swap_remove() and index access methods are intuitive once you realize it's backed by a Vec.
Best for: Projects needing HashMap functionality with predictable iteration order, or where deterministic output matters (CLIs, serialization, testing).
Avoid if: You're doing heavy remove operations in hot paths and order doesn't matter - stick with HashMap for better remove performance.
Rock-solid ordered hash map with predictable performance characteristics
Performance characteristics are well-documented and predictable: O(1) lookup with slightly higher constant factors than HashMap, but iteration is consistently 2-3x faster in my benchmarks. The retain() and swap_remove() methods are particularly useful for hot paths. Memory usage is slightly higher than HashMap due to the index layer, but the density of value storage often compensates.
The 2.x series introduced some breaking changes around entry API behavior, but the migration was straightforward. Serialization with serde preserves insertion order, which has saved me from subtle bugs in config management and API responses. No runtime surprises, no allocation spikes under load, just reliable deterministic behavior.
Best for: Applications requiring predictable iteration order, deterministic behavior, or where iteration performance matters more than insert speed.
Avoid if: You have extremely high insert/remove churn with no iteration needs and memory is critically constrained.
Sign in to write a review
Sign In