Struct Counter
pub struct Counter(/* private fields */);Expand description
Core runtime types and traits used to define and run a crawl. A thread-safe counter using atomic operations.
This is a wrapper around AtomicUsize that provides a more ergonomic API
for counting operations in concurrent environments.
§Example
ⓘ
use spider_core::state::Counter;
let counter = Counter::new();
counter.inc();
counter.add(5);
assert_eq!(counter.get(), 6);Implementations§
§impl Counter
impl Counter
pub fn with_value(value: usize) -> Counter
pub fn with_value(value: usize) -> Counter
Creates a new counter with the specified initial value.
pub fn inc(&self)
pub fn inc(&self)
Increments the counter by 1.
pub fn dec(&self)
pub fn dec(&self)
Decrements the counter by 1.
pub fn swap(&self, value: usize) -> usize
pub fn swap(&self, value: usize) -> usize
Atomically swaps the counter value and returns the old value.
pub fn compare_and_swap(&self, current: usize, new: usize) -> usize
pub fn compare_and_swap(&self, current: usize, new: usize) -> usize
Atomically compares and swaps the value.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Counter
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnwindSafe for Counter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more