prism3_atomic/
lib.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025.
4 *    3-Prism Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9//! # prism3-rust-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//! - Floating-point atomic types: `AtomicF32`, `AtomicF64`
31//! - Reference atomic type: `AtomicRef<T>`
32//!
33//! ## Example
34//!
35//! ```rust
36//! use prism3_atomic::{AtomicI32, Atomic, AtomicNumber};
37//! use std::sync::Arc;
38//! use std::thread;
39//!
40//! // Basic usage
41//! let counter = AtomicI32::new(0);
42//! counter.fetch_inc();
43//! assert_eq!(counter.load(), 1);
44//!
45//! // Concurrent usage
46//! let counter = Arc::new(AtomicI32::new(0));
47//! let mut handles = vec![];
48//!
49//! for _ in 0..10 {
50//!     let counter = counter.clone();
51//!     let handle = thread::spawn(move || {
52//!         for _ in 0..100 {
53//!             counter.fetch_inc();
54//!         }
55//!     });
56//!     handles.push(handle);
57//! }
58//!
59//! for handle in handles {
60//!     handle.join().unwrap();
61//! }
62//!
63//! assert_eq!(counter.load(), 1000);
64//! ```
65//!
66//! ## Author
67//!
68//! Haixing Hu
69
70#![deny(missing_docs)]
71#![deny(unsafe_op_in_unsafe_fn)]
72
73pub mod atomic;
74
75// Re-export all atomic types and traits
76pub use atomic::{
77    Atomic,
78    AtomicBool,
79    AtomicF32,
80    AtomicF64,
81    AtomicI16,
82    AtomicI32,
83    AtomicI64,
84    AtomicI8,
85    AtomicIsize,
86    AtomicNumber,
87    AtomicRef,
88    AtomicU16,
89    AtomicU32,
90    AtomicU64,
91    AtomicU8,
92    AtomicUsize,
93};