API Reference

DashMap

Blazingly fast concurrent HashMap for Rust using sharded locks and lock-free reads.

Official Documentation ↗
CompatibilityThis documentation covers version dashmap 6.x / Rust 1.65+. Check the official docs for the latest API surface.

Installation

cargocargo add dashmap

Methods

Overview

DashMap is a concurrent hash map that splits data across shards, each with its own lock, so many threads can read and write at once without a single global lock.

Core Methods

Use insert, get, remove and entry like a standard map. get returns a reference guard, iter iterates entries, and entry supports atomic read-modify-write patterns.

Usage Notes

Use it for shared registries, counters and caches accessed by many threads. Keep guards short lived and prefer entry for atomic updates to avoid check-then-act races.

Common Pitfalls

Holding a reference guard while acquiring another lock on the same shard deadlocks. Iteration takes shard locks, so doing heavy work inside the loop blocks others. Resizing can be expensive under load.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/dashmap/latest/dashmap/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:03.399Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

  • Shared Value A simple wrapper around T TryReserve Error Traits § Map Implementation detail that is exposed due to generic constraints in public types. (https://docs.rs/dashmap/latest/dashmap/)

FAQ

How does DashMap allow concurrent writes?
It shards the map and locks per shard, so operations on different shards proceed in parallel. Reads take a minimal lock depending on configuration.
What is the deadlock caveat?
A reference returned by get holds a shard lock until dropped. Taking another lock on the same shard while holding it deadlocks, so clone the value or scope the reference tightly.
When is a Mutex HashMap better?
When contention is low or the map is small, a standard HashMap behind a mutex is simpler and often fast enough. DashMap shines under high concurrent access.