pub trait Integer:
Integer
+ FromStr
+ Copy
+ Display
+ Debug
+ Sum
+ NumAssignOps
+ Bounded
+ NumCast
+ Send
+ Sync
+ OverflowingSub
+ CheckedAdd
+ WrappingSub {
type SafeLen: Hash + Integer + NumAssignOps + Bounded + NumCast + One + AddAssign + SubAssign + Copy + PartialEq + Eq + PartialOrd + Ord + Send + Default + Debug + Display;
// Required methods
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>;
fn safe_len(range: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen;
fn f64_to_safe_len(f: f64) -> Self::SafeLen;
fn safe_len_to_f64(len: Self::SafeLen) -> f64;
fn add_len_less_one(a: Self, b: Self::SafeLen) -> Self;
fn sub_len_less_one(a: Self, b: Self::SafeLen) -> Self;
// Provided method
fn safe_max_value() -> Self { ... }
}Expand description
The element trait of the RangeSetBlaze and SortedDisjoint, specifically u8 to u128 (including usize) and i8 to i128 (including isize).
Required Associated Types§
Sourcetype SafeLen: Hash + Integer + NumAssignOps + Bounded + NumCast + One + AddAssign + SubAssign + Copy + PartialEq + Eq + PartialOrd + Ord + Send + Default + Debug + Display
type SafeLen: Hash + Integer + NumAssignOps + Bounded + NumCast + One + AddAssign + SubAssign + Copy + PartialEq + Eq + PartialOrd + Ord + Send + Default + Debug + Display
The type of the length of a RangeSetBlaze. For example, the length of a RangeSetBlaze<u8> is usize. Note
that it can’t be u8 because the length ranges from 0 to 256, which is one too large for u8.
In general, SafeLen will be usize if usize is always large enough. If not, SafeLen will be the smallest unsigned integer
type that is always large enough. However, for u128 and i128, nothing is always large enough so
SafeLen will be u128 and we prohibit the largest value from being used in Integer.
§Examples
use range_set_blaze::{RangeSetBlaze, Integer};
let len: <u8 as Integer>::SafeLen = RangeSetBlaze::from_iter([0u8..=255]).len();
assert_eq!(len, 256);Required Methods§
Sourcefn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
A definition of RangeSetBlaze::from_slice() specific to this integer type.
Sourcefn safe_len(range: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len(range: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
Returns the length of a range without any overflow.
§Example
use range_set_blaze::Integer;
assert_eq!(<u8 as Integer>::safe_len(&(0..=255)), 256);Sourcefn f64_to_safe_len(f: f64) -> Self::SafeLen
fn f64_to_safe_len(f: f64) -> Self::SafeLen
Converts a f64 to Integer::SafeLen using the formula f as Self::SafeLen. For large integer types, this will result in a loss of precision.
Sourcefn safe_len_to_f64(len: Self::SafeLen) -> f64
fn safe_len_to_f64(len: Self::SafeLen) -> f64
Converts Integer::SafeLen to f64 using the formula len as f64. For large integer types, this will result in a loss of precision.
Sourcefn add_len_less_one(a: Self, b: Self::SafeLen) -> Self
fn add_len_less_one(a: Self, b: Self::SafeLen) -> Self
Computes a + (b - 1) as Self
Sourcefn sub_len_less_one(a: Self, b: Self::SafeLen) -> Self
fn sub_len_less_one(a: Self, b: Self::SafeLen) -> Self
Computes a - (b - 1) as Self
Provided Methods§
Sourcefn safe_max_value() -> Self
fn safe_max_value() -> Self
For a given Integer type, returns the largest value that can be used. For all types other than u128 and i128,
this is the same as Self::MAX. For u128 and i128, this is one less than Self::MAX.
§Example
use range_set_blaze::{Integer, RangeSetBlaze};
// for i8, we can use up to 127
let a = RangeSetBlaze::from_iter([i8::MAX]);
// for i128, we can use up to 170141183460469231731687303715884105726
let a = RangeSetBlaze::from_iter([<i128 as Integer>::safe_max_value()]);§Panics
use range_set_blaze::{Integer, RangeSetBlaze};
// for i128, using 170141183460469231731687303715884105727 throws a panic.
let a = RangeSetBlaze::from_iter([i128::MAX]);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.