Skip to main content

ArcAtomicSignedCount

Struct ArcAtomicSignedCount 

Source
pub struct ArcAtomicSignedCount { /* private fields */ }
Expand description

Shared-owner wrapper around AtomicSignedCount.

This type is a convenience newtype for Arc<AtomicSignedCount>. Cloning an ArcAtomicSignedCount clones the shared owner handle, so all clones operate on the same underlying signed counter.

§Example

use qubit_atomic::ArcAtomicSignedCount;

let counter = ArcAtomicSignedCount::zero();
let shared = counter.clone();

shared.sub(3);
assert_eq!(counter.get(), -3);
assert_eq!(counter.strong_count(), 2);

Implementations§

Source§

impl ArcAtomicSignedCount

Source

pub fn new(value: isize) -> Self

Creates a new shared signed atomic counter.

§Parameters
  • value - The initial counter value.
§Returns

A shared signed counter wrapper initialized to value.

Source

pub fn zero() -> Self

Creates a new shared signed counter initialized to zero.

§Returns

A shared signed counter wrapper whose current value is zero.

Source

pub fn from_count(counter: AtomicSignedCount) -> Self

Wraps an existing AtomicSignedCount in an Arc.

§Parameters
  • counter - The signed counter container to share.
§Returns

A shared signed counter wrapper owning counter.

Source

pub fn from_arc(inner: Arc<AtomicSignedCount>) -> Self

Wraps an existing shared signed atomic counter.

§Parameters
  • inner - The shared signed atomic counter to wrap.
§Returns

A wrapper around inner.

Source

pub fn as_arc(&self) -> &Arc<AtomicSignedCount>

Returns the underlying Arc without cloning it.

§Returns

A shared reference to the underlying Arc<AtomicSignedCount>.

Source

pub fn into_arc(self) -> Arc<AtomicSignedCount>

Consumes this wrapper and returns the underlying Arc.

§Returns

The underlying Arc<AtomicSignedCount>.

Source

pub fn strong_count(&self) -> usize

Returns the number of strong Arc owners.

§Returns

The current strong reference count of the shared signed counter.

Methods from Deref<Target = AtomicSignedCount>§

Source

pub fn get(&self) -> isize

Gets the current counter value.

§Returns

The current counter value.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(-7);
assert_eq!(counter.get(), -7);
Source

pub fn is_zero(&self) -> bool

Returns whether the current counter value is zero.

§Returns

true if the current value is zero, otherwise false.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::zero();
assert!(counter.is_zero());
Source

pub fn is_positive(&self) -> bool

Returns whether the current counter value is greater than zero.

§Returns

true if the current value is greater than zero, otherwise false.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(1);
assert!(counter.is_positive());
Source

pub fn is_negative(&self) -> bool

Returns whether the current counter value is less than zero.

§Returns

true if the current value is less than zero, otherwise false.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(-1);
assert!(counter.is_negative());
Source

pub fn inc(&self) -> isize

Increments the counter by one and returns the new value.

§Returns

The counter value after the increment.

§Panics

Panics if the increment would overflow isize::MAX.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::zero();
assert_eq!(counter.inc(), 1);
Source

pub fn dec(&self) -> isize

Decrements the counter by one and returns the new value.

§Returns

The counter value after the decrement.

§Panics

Panics if the decrement would underflow isize::MIN.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::zero();
assert_eq!(counter.dec(), -1);
Source

pub fn add(&self, delta: isize) -> isize

Adds delta to the counter and returns the new value.

§Parameters
  • delta - The amount to add. It may be negative.
§Returns

The counter value after the addition.

§Panics

Panics if the addition would overflow or underflow the signed range.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(2);
assert_eq!(counter.add(-5), -3);
Source

pub fn try_add(&self, delta: isize) -> Option<isize>

Tries to add delta to the counter.

§Parameters
  • delta - The amount to add. It may be negative.
§Returns

Some(new_value) if the addition succeeds, or None if it would overflow or underflow the signed range. On None, the counter is left unchanged.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(-2);
assert_eq!(counter.try_add(5), Some(3));
Source

pub fn sub(&self, delta: isize) -> isize

Subtracts delta from the counter and returns the new value.

§Parameters
  • delta - The amount to subtract. It may be negative.
§Returns

The counter value after the subtraction.

§Panics

Panics if the subtraction would overflow or underflow the signed range.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(2);
assert_eq!(counter.sub(5), -3);
Source

pub fn try_sub(&self, delta: isize) -> Option<isize>

Tries to subtract delta from the counter.

§Parameters
  • delta - The amount to subtract. It may be negative.
§Returns

Some(new_value) if the subtraction succeeds, or None if it would overflow or underflow the signed range. On None, the counter is left unchanged.

§Example
use qubit_atomic::AtomicSignedCount;

let counter = AtomicSignedCount::new(2);
assert_eq!(counter.try_sub(5), Some(-3));

Trait Implementations§

Source§

impl Clone for ArcAtomicSignedCount

Source§

fn clone(&self) -> Self

Clones the shared owner handle.

§Returns

A new wrapper pointing to the same underlying signed atomic counter.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ArcAtomicSignedCount

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the current counter value and sharing state for debugging.

§Parameters
  • f - The formatter receiving the debug representation.
§Returns

A formatting result from the formatter.

Source§

impl Default for ArcAtomicSignedCount

Source§

fn default() -> Self

Creates a zero-valued shared signed atomic counter.

§Returns

A shared signed counter wrapper whose current value is zero.

Source§

impl Deref for ArcAtomicSignedCount

Source§

fn deref(&self) -> &Self::Target

Dereferences to the underlying AtomicSignedCount.

§Returns

A shared reference to the signed atomic counter.

Source§

type Target = AtomicSignedCount

The resulting type after dereferencing.
Source§

impl Display for ArcAtomicSignedCount

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the current counter value with decimal display formatting.

§Parameters
  • f - The formatter receiving the displayed value.
§Returns

A formatting result from the formatter.

Source§

impl From<Arc<AtomicSignedCount>> for ArcAtomicSignedCount

Source§

fn from(inner: Arc<AtomicSignedCount>) -> Self

Converts an existing shared signed atomic counter into its wrapper.

§Parameters
  • inner - The shared signed atomic counter to wrap.
§Returns

A wrapper around inner.

Source§

impl From<AtomicSignedCount> for ArcAtomicSignedCount

Source§

fn from(counter: AtomicSignedCount) -> Self

Converts a signed atomic counter into a shared signed counter wrapper.

§Parameters
  • counter - The signed counter container to share.
§Returns

A shared signed counter wrapper owning counter.

Source§

impl From<isize> for ArcAtomicSignedCount

Source§

fn from(value: isize) -> Self

Converts an initial counter value into a shared signed atomic counter.

§Parameters
  • value - The initial counter value.
§Returns

A shared signed counter wrapper initialized to value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.