qubit_atomic/lib.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! # qubit-atomic
10//!
11//! User-friendly atomic operations wrapper providing JDK-like atomic API.
12//!
13//! This crate provides easy-to-use atomic types with reasonable default memory
14//! orderings, similar to Java's `java.util.concurrent.atomic` package.
15//!
16//! ## Design Goals
17//!
18//! - **Ease of Use**: Hides memory ordering complexity with reasonable defaults
19//! - **Completeness**: Provides high-level operations similar to JDK atomic
20//! - **Safety**: Guarantees memory safety and thread safety
21//! - **Performance**: Zero-cost abstraction with no additional overhead
22//! - **Flexibility**: Exposes underlying types via `inner()` for advanced users
23//!
24//! ## Features
25//!
26//! - Boolean atomic type: `AtomicBool`
27//! - Integer atomic types: `AtomicI8`, `AtomicU8`, `AtomicI16`, `AtomicU16`,
28//! `AtomicI32`, `AtomicU32`, `AtomicI64`, `AtomicU64`, `AtomicIsize`,
29//! `AtomicUsize`
30//! - Counter atomic types: `AtomicCounter`, `AtomicSignedCounter`
31//! - Floating-point atomic types: `AtomicF32`, `AtomicF64`
32//! - Reference atomic type: `AtomicRef<T>`
33//!
34//! ## Example
35//!
36//! ```rust
37//! use qubit_atomic::{AtomicI32, Atomic, AtomicNumber};
38//! use std::sync::Arc;
39//! use std::thread;
40//!
41//! // Basic usage
42//! let counter = AtomicI32::new(0);
43//! counter.fetch_inc();
44//! assert_eq!(counter.load(), 1);
45//!
46//! // Concurrent usage
47//! let counter = Arc::new(AtomicI32::new(0));
48//! let mut handles = vec![];
49//!
50//! for _ in 0..10 {
51//! let counter = counter.clone();
52//! let handle = thread::spawn(move || {
53//! for _ in 0..100 {
54//! counter.fetch_inc();
55//! }
56//! });
57//! handles.push(handle);
58//! }
59//!
60//! for handle in handles {
61//! handle.join().unwrap();
62//! }
63//!
64//! assert_eq!(counter.load(), 1000);
65//! ```
66//!
67//! ## Author
68//!
69//! Haixing Hu
70
71#![deny(missing_docs)]
72#![deny(unsafe_op_in_unsafe_fn)]
73
74pub mod atomic;
75
76// Re-export all atomic types and traits
77pub use atomic::{
78 Atomic,
79 AtomicBool,
80 AtomicCounter,
81 AtomicF32,
82 AtomicF64,
83 AtomicI8,
84 AtomicI16,
85 AtomicI32,
86 AtomicI64,
87 AtomicIsize,
88 AtomicNumber,
89 AtomicRef,
90 AtomicSignedCounter,
91 AtomicU8,
92 AtomicU16,
93 AtomicU32,
94 AtomicU64,
95 AtomicUsize,
96};