pub trait Steppable: Clone + PartialOrd + Ord {
    // Required methods
    fn step_incr(&self) -> Self;
    fn step_decr(&self) -> Self;
    fn range_size<N: Borrow<Self>, R: RangeBounds<N>>(
        range: R
    ) -> Result<Self, RangeOperationError>;

    // Provided method
    fn range_tuple_size<N: Borrow<Self>>(
        start: N,
        end: N
    ) -> Result<Self, RangeOperationError> { ... }
}
Expand description

Trait representing number types which can be incrementally stepped.

Safety

This trait is not unsafe, so do not use custom implementers of this trait in unsafe contexts (e.g. a custom NumInRange as indexes to track initialized buckets in a custom HashMap) without auditing the exact implementation.

Required Methods§

source

fn step_incr(&self) -> Self

Return the smallest possible value larger than the input value. Should saturate at the maximum possible value.

source

fn step_decr(&self) -> Self

Return the largest possible value smaller than the input value. Should saturate at the minimum possible value.

source

fn range_size<N: Borrow<Self>, R: RangeBounds<N>>( range: R ) -> Result<Self, RangeOperationError>

Return the size of the range.

Provided Methods§

source

fn range_tuple_size<N: Borrow<Self>>( start: N, end: N ) -> Result<Self, RangeOperationError>

Functions like Self::range_size given input start..=end.

Implementors§

source§

impl Steppable for NonNanFloat<f32>

Considerations for stepping floating-point types:

  • Steps are performed to the next possible representable value, so the size of the step varies with the original number’s magnitude.
  • Approximations and floating-point error can lead to miniscule gaps and other unexpected behaviors. For example, 0.3-0.2-0.1=-2.7755575615628914e-17 will not be contained in a nonnegative range starting at 0.
source§

impl Steppable for NonNanFloat<f64>

Considerations for stepping floating-point types:

  • Steps are performed to the next possible representable value, so the size of the step varies with the original number’s magnitude.
  • Approximations and floating-point error can lead to miniscule gaps and other unexpected behaviors. For example, 0.3-0.2-0.1=-2.7755575615628914e-17 will not be contained in a nonnegative range starting at 0.
source§

impl<T: PrimInt> Steppable for T