atomic-plus

Crates.ioatomic-plus
lib.rsatomic-plus
version0.1.1
created_at2025-12-31 09:19:51.296221+00
updated_at2025-12-31 09:24:08.808258+00
descriptiontype extensions for the atomic standard library.
homepage
repositoryhttps://github.com/0xhappyboy/atomic-plus
max_upload_size
id2014335
size41,660
happy₿oy (0xhappyboy)

documentation

README

atomic-plus

type extensions for the atomic standard library.

License

简体中文 | English

Features

  • AtomicF64: Atomic operations for 64-bit floating point numbers
  • AtomicF32: Atomic operations for 32-bit floating point numbers
  • AtomicBoolArray: Space-efficient atomic boolean array (1 bit per boolean)
  • AtomicShortString: Fixed-length atomic string (max 32 ASCII characters)
  • AtomicTimestamp: Nanosecond-precision atomic timestamp
  • AtomicPtr: Generic atomic pointer wrapper
  • AtomicRc: Atomic reference counting (similar to std::rc::Rc but with atomic operations)

Installation

Add to your Cargo.toml:

[dependencies]
atomic-ext = "0.1.0"

Usage

use atomic_ext::{AtomicF64, AtomicBoolArray};
use std::sync::atomic::Ordering;

// Create an atomic float
let atomic_float = AtomicF64::new(10.5);
atomic_float.store(20.5, Ordering::Relaxed);
let value = atomic_float.load(Ordering::Relaxed);

// Create an atomic boolean array
let bool_array = AtomicBoolArray::new(100);
bool_array.set(42, true, Ordering::Relaxed);
let is_true = bool_array.get(42, Ordering::Relaxed);

Features

  • Thread-safe: All types are designed for concurrent access
  • No unsafe code required: Safe API surface
  • High performance: Built on standard library atomics
  • Comprehensive tests: Includes concurrent test scenarios

Notes

  • AtomicF64 and AtomicF32 store floats using their bit patterns
  • AtomicBoolArray uses 1/64th the memory of Vec<AtomicBool>
  • AtomicRc is not Send/Sync by default (contains raw pointers)
  • AtomicTimestamp provides nanosecond precision

Testing

Run tests with:

cargo test
Commit count: 0

cargo fmt