Trait range_union_find::Steppable
source · 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§
sourcefn step_incr(&self) -> Self
fn step_incr(&self) -> Self
Return the smallest possible value larger than the input value. Should saturate at the maximum possible value.
sourcefn step_decr(&self) -> Self
fn step_decr(&self) -> Self
Return the largest possible value smaller than the input value. Should saturate at the minimum possible value.
sourcefn range_size<N: Borrow<Self>, R: RangeBounds<N>>(
range: R
) -> Result<Self, RangeOperationError>
fn range_size<N: Borrow<Self>, R: RangeBounds<N>>( range: R ) -> Result<Self, RangeOperationError>
Return the size of the range.
Provided Methods§
sourcefn range_tuple_size<N: Borrow<Self>>(
start: N,
end: N
) -> Result<Self, RangeOperationError>
fn range_tuple_size<N: Borrow<Self>>( start: N, end: N ) -> Result<Self, RangeOperationError>
Functions like Self::range_size
given input start..=end
.
Implementors§
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.
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.