# vorner/arc-swap architecture

> Architecture diagram of the GitHub repository vorner/arc-swap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vorner/arc-swap
- Repository: https://github.com/vorner/arc-swap

## Overview

ArcSwap is a Rust library providing atomic replacement and read access to reference-counted values, optimized for read-heavy workloads. The principal workflow is that application code loads a guarded value or stores a replacement; the selected strategy protects readers and safely reclaims replaced values. Supporting capabilities include alternative locking, weak-pointer swaps, projected and cached access, and Serde integration. The graph reflects documented behavior and relationships visible in the excerpts and SOURCE INDEX; unsampled implementation details are not assumed.

Main entry points: [`src/lib.rs`](https://github.com/vorner/arc-swap/blob/master/src/lib.rs) (ArcSwap API), [`src/strategy/mod.rs`](https://github.com/vorner/arc-swap/blob/master/src/strategy/mod.rs) (Strategy selection), [`src/strategy/hybrid.rs`](https://github.com/vorner/arc-swap/blob/master/src/strategy/hybrid.rs) (Hybrid protection), [`src/debt/mod.rs`](https://github.com/vorner/arc-swap/blob/master/src/debt/mod.rs) (Debt management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_arc_swap["ArcSwap API<br/>[lib.rs]"]
  node_raw_pointer["Raw pointer adapters<br/>[as_raw.rs]"]
end

subgraph group_protection["Reader Protection"]
  node_reference_counts["Reference-count abstraction<br/>[ref_cnt.rs]"]
  node_strategy["Strategy selection<br/>[mod.rs]"]
  node_hybrid["Hybrid protection<br/>[hybrid.rs]"]
  node_rw_lock["RwLock strategy<br/>[rw_lock.rs]"]
  node_debt["Debt management<br/>[mod.rs]"]
  node_fast_slots["Fast debt slots<br/>[fast.rs]"]
  node_helping_slots["Helping slots<br/>[helping.rs]"]
  node_debt_list["Thread debt list<br/>[list.rs]"]
end

subgraph group_extensions["Access Extensions"]
  node_access["Projected access<br/>[access.rs]"]
  node_cache["Cached access<br/>[cache.rs]"]
  node_weak["Weak pointer API<br/>[weak.rs]"]
  node_serde["Serde support<br/>[serde.rs]"]
end

node_user(("Application code"))

node_user -->|"loads and stores"| node_arc_swap
node_arc_swap -->|"uses"| node_strategy
node_arc_swap -->|"exposes"| node_access
node_arc_swap -->|"exposes"| node_cache
node_arc_swap -->|"exposes"| node_weak
node_arc_swap -->|"integrates"| node_serde
node_strategy -->|"selects default"| node_hybrid
node_strategy -->|"supports alternative"| node_rw_lock
node_hybrid -->|"manages debts"| node_debt
node_hybrid -->|"protects values"| node_reference_counts
node_hybrid -->|"uses pointers"| node_raw_pointer
node_rw_lock -->|"adjusts counts"| node_reference_counts
node_rw_lock -->|"adapts pointers"| node_raw_pointer
node_debt -->|"uses nodes"| node_debt_list
node_debt -->|"uses slots"| node_fast_slots
node_debt -->|"uses slots"| node_helping_slots
node_debt_list -->|"allocates"| node_fast_slots
node_debt_list -->|"supports helping"| node_helping_slots
node_access -->|"uses guards"| node_strategy
node_access -->|"abstracts pointers"| node_reference_counts
node_cache -->|"checks pointers"| node_reference_counts
node_cache -->|"loads through"| node_strategy

click node_arc_swap "https://github.com/vorner/arc-swap/blob/master/src/lib.rs"
click node_raw_pointer "https://github.com/vorner/arc-swap/blob/master/src/as_raw.rs"
click node_reference_counts "https://github.com/vorner/arc-swap/blob/master/src/ref_cnt.rs"
click node_strategy "https://github.com/vorner/arc-swap/blob/master/src/strategy/mod.rs"
click node_hybrid "https://github.com/vorner/arc-swap/blob/master/src/strategy/hybrid.rs"
click node_rw_lock "https://github.com/vorner/arc-swap/blob/master/src/strategy/rw_lock.rs"
click node_debt "https://github.com/vorner/arc-swap/blob/master/src/debt/mod.rs"
click node_fast_slots "https://github.com/vorner/arc-swap/blob/master/src/debt/fast.rs"
click node_helping_slots "https://github.com/vorner/arc-swap/blob/master/src/debt/helping.rs"
click node_debt_list "https://github.com/vorner/arc-swap/blob/master/src/debt/list.rs"
click node_access "https://github.com/vorner/arc-swap/blob/master/src/access.rs"
click node_cache "https://github.com/vorner/arc-swap/blob/master/src/cache.rs"
click node_weak "https://github.com/vorner/arc-swap/blob/master/src/weak.rs"
click node_serde "https://github.com/vorner/arc-swap/blob/master/src/serde.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_arc_swap,node_raw_pointer toneBlue
class node_reference_counts,node_strategy,node_hybrid,node_rw_lock,node_debt,node_fast_slots,node_helping_slots,node_debt_list toneAmber
class node_access,node_cache,node_weak,node_serde toneMint
class node_user toneIndigo
```

## Components

### Public API

- [ArcSwap API](https://github.com/vorner/arc-swap/blob/master/src/lib.rs): `src/lib.rs`
- [Raw pointer adapters](https://github.com/vorner/arc-swap/blob/master/src/as_raw.rs): `src/as_raw.rs`

### Reader Protection

- [Reference-count abstraction](https://github.com/vorner/arc-swap/blob/master/src/ref_cnt.rs): `src/ref_cnt.rs`
- [Strategy selection](https://github.com/vorner/arc-swap/blob/master/src/strategy/mod.rs): `src/strategy/mod.rs`
- [Hybrid protection](https://github.com/vorner/arc-swap/blob/master/src/strategy/hybrid.rs): `src/strategy/hybrid.rs`
- [RwLock strategy](https://github.com/vorner/arc-swap/blob/master/src/strategy/rw_lock.rs): `src/strategy/rw_lock.rs`
- [Debt management](https://github.com/vorner/arc-swap/blob/master/src/debt/mod.rs): `src/debt/mod.rs`
- [Fast debt slots](https://github.com/vorner/arc-swap/blob/master/src/debt/fast.rs): `src/debt/fast.rs`
- [Helping slots](https://github.com/vorner/arc-swap/blob/master/src/debt/helping.rs): `src/debt/helping.rs`
- [Thread debt list](https://github.com/vorner/arc-swap/blob/master/src/debt/list.rs): `src/debt/list.rs`

### Access Extensions

- [Projected access](https://github.com/vorner/arc-swap/blob/master/src/access.rs): `src/access.rs`
- [Cached access](https://github.com/vorner/arc-swap/blob/master/src/cache.rs): `src/cache.rs`
- [Weak pointer API](https://github.com/vorner/arc-swap/blob/master/src/weak.rs): `src/weak.rs`
- [Serde support](https://github.com/vorner/arc-swap/blob/master/src/serde.rs): `src/serde.rs`

### Other components

- **Application code**

## Connections

- Application code → ArcSwap API: loads and stores (evidence: `README.md`)
- ArcSwap API → Strategy selection: uses (evidence: `src/lib.rs`)
- ArcSwap API → Projected access: exposes (evidence: `src/lib.rs`)
- ArcSwap API → Cached access: exposes (evidence: `src/lib.rs`)
- ArcSwap API → Weak pointer API: exposes (evidence: `src/lib.rs`)
- ArcSwap API → Serde support: integrates (evidence: `src/lib.rs`)
- Strategy selection → Hybrid protection: selects default (evidence: `src/strategy/mod.rs`)
- Strategy selection → RwLock strategy: supports alternative (evidence: `src/strategy/mod.rs`)
- Hybrid protection → Debt management: manages debts (evidence: `src/strategy/hybrid.rs`)
- Hybrid protection → Reference-count abstraction: protects values (evidence: `src/strategy/hybrid.rs`)
- Hybrid protection → Raw pointer adapters: uses pointers (evidence: `src/strategy/hybrid.rs`)
- RwLock strategy → Reference-count abstraction: adjusts counts (evidence: `src/strategy/rw_lock.rs`)
- RwLock strategy → Raw pointer adapters: adapts pointers (evidence: `src/strategy/rw_lock.rs`)
- Debt management → Thread debt list: uses nodes (evidence: `src/debt/mod.rs`)
- Debt management → Fast debt slots: uses slots (evidence: `src/debt/mod.rs`)
- Debt management → Helping slots: uses slots (evidence: `src/debt/mod.rs`)
- Thread debt list → Fast debt slots: allocates (evidence: `src/debt/list.rs`)
- Thread debt list → Helping slots: supports helping (evidence: `src/debt/list.rs`)
- Projected access → Strategy selection: uses guards (evidence: `src/access.rs`)
- Projected access → Reference-count abstraction: abstracts pointers (evidence: `src/access.rs`)
- Cached access → Reference-count abstraction: checks pointers (evidence: `src/cache.rs`)
- Cached access → Strategy selection: loads through (evidence: `src/cache.rs`)
