Traits over atomic primitive integer types.
fn incr<T: AtomicInt>(value: &T) -> Result<<T as AtomicInt>::Prim, <T as AtomicInt>::Prim> {
value.fetch_update(
Ordering::SeqCst,
Ordering::SeqCst,
|i| Some(if i == T::MAX { T::MIN } else { i + T::ONE })
)
}
let value = AtomicU8::new(255);
assert_eq!(incr(&value), Ok(255));
assert_eq!(incr(&value), Ok(0));- Enable feature
nightlyto getas_mut_ptrwhen you have a nightly compiler available. - Rust 1.45.0 or newer is required.
Copyright (c) 2020-2023 James Laver, atomic_prim_traits contributors.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.