std-method
Atomic bitwise fetch operations
Modify bits with one read-modify-write operation. These methods return the previous integer, not the new bit pattern. NAND negates the bitwise AND across the complete integer width. Expected stdout (not executed): 0100 Common mistake: Updating a shared bit mask with separate load and store operations.
Formal Syntax & Structure
rust syntaxrust
fetch_or(mask, order); fetch_and(mask, order); fetch_xor(mask, order); fetch_nand(mask, order)Working Example
Example Snippetrust
fn main() { use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; let flags = AtomicUsize::new(0b0011); flags.fetch_or(0b0100, Relaxed); flags.fetch_and(0b0110, Relaxed); flags.fetch_xor(0b0010, Relaxed); println!("{:04b}", flags.load(Relaxed));}