wrc 2.1.0

A thread-safe weighted reference counting smart-pointer for Rust.
Documentation
# WRC

[![Build Status](https://drone.harton.nz/api/badges/james/wrc/status.svg?ref=refs/heads/main)](https://drone.harton.nz/james/wrc)

A thread-safe weighted reference counting smart-pointer for Rust.

## Overview

By using weights instead of direct reference counting WRC requires roughly half as many synchronisation operations and writes to the heap. Every time a WRC is cloned its weight is split in two, with half allocated to the parent and half allocated to the child. When a WRC is dropped its weight is removed from the total. When the total weight declines to zero then the referenced object is dropped.

## Features

- Thread-safe.
- Efficient.
- Lightweight.

## Examples

Sharing some immutable data between threads:

```rust
use wrc::Wrc;
use std::thread;

let five = Wrc::new(5);

for _ in 0..10 {
    let five = five.clone();
    thread::spawn(move || {
        println!("{:?}", five);
    });
}
```

Sharing a mutable `AtomicUsize`:

```rust
use wrc::Wrc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;

let val = Wrc::new(AtomicUsize::new(5));

for _ in 0..10 {
    let val = val.clone();

    thread::spawn(move || {
        let v = val.fetch_add(1, Ordering::SeqCst);
        println!("{:?}", v);
    });
}
```

## Benchmarks

Simple benchmarks have been built using [Criterion](https://crates.io/crates/criterion). Feel free to run `cargo bench` to compare them. Each benchmark allocates an owned string and places it within the smart pointer before cloning and dropping the pointer 32 times.

Example results (2026, Linux):

```
arc 32                  time:   [393.03 ns 394.70 ns 396.35 ns]
rc 32                   time:   [50.165 ns 50.917 ns 51.705 ns]
wrc 32                  time:   [302.98 ns 305.44 ns 308.14 ns]
```

Wrc is faster than Arc because weight-splitting avoids atomic operations on most clones. Results will vary by machine and workload.

## License

This software is licensed under the terms of the
[HL3-FULL](https://firstdonoharm.dev), see the `LICENSE.md` file included with
this package for the terms.

This license actively proscribes this software being used by and for some
industries, countries and activities. If your usage of this software doesn't
comply with the terms of this license, then [contact me](mailto:james@harton.nz)
with the details of your use-case to organise the purchase of a license - the
cost of which may include a donation to a suitable charity or NGO.