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§
Sourceconst START: Self
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.
Sourceconst START_INT: Self::Int
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§
Sourcefn checked_add(this: Self, offset: Self::Int) -> Option<Self>
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.
Sourcefn checked_sub(this: Self, offset: Self::Int) -> Option<Self>
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".