Skip to main content

IntegerIdCounter

Trait IntegerIdCounter 

Source
pub trait IntegerIdCounter: IntegerId + IntegerIdContiguous {
    const START: Self;
    const START_INT: Self::Int;

    // Provided methods
    fn checked_add(this: Self, offset: Self::Int) -> Option<Self> { ... }
    fn checked_sub(this: Self, offset: Self::Int) -> Option<Self> { ... }
}
Expand description

An IntegerId that can be sensibly used as a counter, starting at a Self::START value and being incremented from there.

This is used by the intid-allocator crate to provide an atomic counter to allocate new ids. It also provides more complex allocators that can reuse ids that have been freed.

This type cannot be implemented for uninhabited types like core::convert::Infallible or !, as there is no valid implementation of Self::START.

Required Associated Constants§

Source

const START: Self

Where a counter a should start from.

This should be the Default value if one is defined. It is usually equal to the IntegerId::MIN_ID, but this is not required.

Source

const START_INT: Self::Int

The value of Self::START as a T::Int.

This is necessary because trait methods (IntegerId::to_int) can not currently be const methods.

Provided Methods§

Source

fn checked_add(this: Self, offset: Self::Int) -> Option<Self>

Increment this value by the specified offset, returning None if the value overflows or is invalid.

This should behave consistently with IntegerIdContiguous and IntegerId::from_int_checked. However, that can not be relied upon for memory safety.

This is implemented as an associated method to avoid namespace pollution.

Source

fn checked_sub(this: Self, offset: Self::Int) -> Option<Self>

Increment this value by the specified offset, returning None if the value overflows or is invalid.

This should behave consistently with IntegerIdContiguous and IntegerId::from_int_checked. However, that can not be relied upon for memory safety.

This is implemented as an associated method to avoid namespace pollution.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IntegerIdCounter for NonMaxU8

Source§

const START: Self = nonmax::NonMaxU8::ZERO

Source§

const START_INT: Self::Int = 0

Source§

impl IntegerIdCounter for NonMaxU16

Source§

const START: Self = nonmax::NonMaxU16::ZERO

Source§

const START_INT: Self::Int = 0

Source§

impl IntegerIdCounter for NonMaxU32

Source§

const START: Self = nonmax::NonMaxU32::ZERO

Source§

const START_INT: Self::Int = 0

Source§

impl IntegerIdCounter for NonMaxU64

Source§

const START: Self = nonmax::NonMaxU64::ZERO

Source§

const START_INT: Self::Int = 0

Source§

impl IntegerIdCounter for NonMaxU128

Source§

const START: Self = nonmax::NonMaxU128::ZERO

Source§

const START_INT: Self::Int = 0

Source§

impl IntegerIdCounter for NonMaxUsize

Source§

const START: Self = nonmax::NonMaxUsize::ZERO

Source§

const START_INT: Self::Int = 0

Source§

impl IntegerIdCounter for NonZeroU8

Source§

impl IntegerIdCounter for NonZeroU16

Source§

impl IntegerIdCounter for NonZeroU32

Source§

impl IntegerIdCounter for NonZeroU64

Source§

impl IntegerIdCounter for NonZeroU128

Source§

impl IntegerIdCounter for NonZeroUsize

Source§

impl IntegerIdCounter for u8

Source§

const START: Self = 0

Source§

const START_INT: Self = 0

Source§

impl IntegerIdCounter for u16

Source§

const START: Self = 0

Source§

const START_INT: Self = 0

Source§

impl IntegerIdCounter for u32

Source§

const START: Self = 0

Source§

const START_INT: Self = 0

Source§

impl IntegerIdCounter for u64

Source§

const START: Self = 0

Source§

const START_INT: Self = 0

Source§

impl IntegerIdCounter for u128

Source§

const START: Self = 0

Source§

const START_INT: Self = 0

Source§

impl IntegerIdCounter for usize

Source§

const START: Self = 0

Source§

const START_INT: Self = 0

Implementors§

Source§

impl<T: IntegerIdCounter> IntegerIdCounter for OrderByInt<T>

Source§

const START: Self

Source§

const START_INT: Self::Int = T::START_INT