pub trait Integer:
Copy
+ PartialEq
+ PartialOrd
+ Ord
+ Debug
+ Send
+ Sync {
type SafeLen: Hash + Copy + PartialEq + PartialOrd + Zero + One + AddAssign + SubAssign;
Show 15 methods
// Required methods
fn checked_add_one(self) -> Option<Self>;
fn add_one(self) -> Self;
fn sub_one(self) -> Self;
fn assign_sub_one(&mut self);
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>;
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>;
fn min_value() -> Self;
fn max_value() -> Self;
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>;
fn safe_len(range: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen;
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen;
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64;
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self;
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self;
// Provided method
fn exhausted_range() -> RangeInclusive<Self> { ... }
}Expand description
Represents elements that can be used within RangeSetBlaze and as keys in RangeMapBlaze.
This includes integer types from u8 to u128 (including usize), i8 to i128 (including isize),
as well as char, Ipv4Addr, and Ipv6Addr.
Required Associated Types§
Sourcetype SafeLen: Hash + Copy + PartialEq + PartialOrd + Zero + One + AddAssign + SubAssign
type SafeLen: Hash + Copy + PartialEq + PartialOrd + Zero + One + AddAssign + SubAssign
The type representing the safe length for a RangeSetBlaze. For example, the length of a RangeSetBlaze<u8> is u16 to handle ranges up to 256 elements.
For larger types like u128, this is represented by a custom type UIntPlusOne<u128>.
§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 checked_add_one(self) -> Option<Self>
fn checked_add_one(self) -> Option<Self>
Attempts to add one to the current value, returning None if the operation would overflow.
Sourcefn add_one(self) -> Self
fn add_one(self) -> Self
Adds one to the current value, panicking in debug mode if the operation overflows.
§Examples
use range_set_blaze::Integer;
assert_eq!(5u8.add_one(), 6);Sourcefn sub_one(self) -> Self
fn sub_one(self) -> Self
Subtracts one from the current value, panicking in debug mode if the operation underflows.
§Examples
use range_set_blaze::Integer;
assert_eq!(5u8.sub_one(), 4);Sourcefn assign_sub_one(&mut self)
fn assign_sub_one(&mut self)
Subtracts one from the current value and assigns it back to self.
Sourcefn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
Advances the iterator for the given range by one step, returning the next value or None if the range is exhausted.
This method needs to be defined on each type of interest because the core::Step trait is not stable yet.
Sourcefn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
Advances the iterator for the given range in reverse by one step, returning the previous value or None if the range is exhausted.
This method needs to be defined on each type of interest because the core::Step trait is not stable yet.
Sourcefn min_value() -> Self
fn min_value() -> Self
Returns the minimum value that can be represented by the type.
§Examples
use range_set_blaze::Integer;
assert_eq!(u8::min_value(), 0);Sourcefn max_value() -> Self
fn max_value() -> Self
Returns the maximum value that can be represented by the type.
§Examples
use range_set_blaze::Integer;
assert_eq!(u8::max_value(), 255);Sourcefn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
Creates a RangeSetBlaze from a slice, specific to the integer type.
Sourcefn safe_len(range: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len(range: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
Calculates the length of a range without overflow.
§Examples
use range_set_blaze::Integer;
assert_eq!(<u8 as Integer>::safe_len(&(0..=255)), 256);Sourcefn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn f64_to_safe_len_lossy(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_lossy(len: Self::SafeLen) -> f64
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
Converts Integer::SafeLen to f64, potentially losing precision for large values.
Sourcefn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
Computes self + (b - 1) where b is of type Integer::SafeLen.
Sourcefn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Computes self - (b - 1) where b is of type Integer::SafeLen.
Provided Methods§
Sourcefn exhausted_range() -> RangeInclusive<Self>
fn exhausted_range() -> RangeInclusive<Self>
Returns an exhausted range, which is a range that starts from the maximum value and ends at the minimum value. This results in an empty range.
§Examples
use range_set_blaze::Integer;
let range = u8::exhausted_range();
assert!(range.is_empty());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.
Implementations on Foreign Types§
Source§impl Integer for char
impl Integer for char
type SafeLen = u32
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for i8
impl Integer for i8
type SafeLen = u16
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for i16
impl Integer for i16
type SafeLen = u32
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for i32
impl Integer for i32
type SafeLen = u64
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for i64
impl Integer for i64
type SafeLen = u128
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for i128
impl Integer for i128
Source§fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
Computes the inclusive end of a range starting at self with length b,
by returning self + (b - 1).
§Panics
In debug builds, panics if b is zero or too large to compute a valid result.
In release builds, this will either panic or wrap on overflow; the result may be meaningless,
but it is always defined and safe (never causes undefined behavior)
Source§fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Computes the inclusive start of a range ending at self with length b,
by returning self - (b - 1).
§Panics
In debug builds, panics if b is zero or too large to compute a valid result.
In release builds, this will either panic or wrap on overflow; the result may be meaningless,
but it is always defined and safe (never causes undefined behavior).
type SafeLen = UIntPlusOne<u128>
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
Source§impl Integer for isize
impl Integer for isize
type SafeLen = u128
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for u8
impl Integer for u8
type SafeLen = u16
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for u16
impl Integer for u16
type SafeLen = u32
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for u32
impl Integer for u32
type SafeLen = u64
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for u64
impl Integer for u64
type SafeLen = u128
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for u128
impl Integer for u128
Source§fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
Computes the inclusive end of a range starting at self with length b,
by returning self + (b - 1).
§Panics
In debug builds, panics if b is zero or too large to compute a valid result.
In release builds, this will either panic or wrap on overflow; the result may be meaningless,
but it is always defined and safe (never causes undefined behavior)
Source§fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Computes the inclusive start of a range ending at self with length b,
by returning self - (b - 1).
§Panics
In debug builds, panics if b is zero or too large to compute a valid result.
In release builds, this will either panic or wrap on overflow; the result may be meaningless,
but it is always defined and safe (never causes undefined behavior).
type SafeLen = UIntPlusOne<u128>
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
Source§impl Integer for usize
impl Integer for usize
type SafeLen = u128
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for Ipv4Addr
impl Integer for Ipv4Addr
type SafeLen = u64
fn checked_add_one(self) -> Option<Self>
fn add_one(self) -> Self
fn sub_one(self) -> Self
fn assign_sub_one(&mut self)
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn min_value() -> Self
fn max_value() -> Self
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§impl Integer for Ipv6Addr
impl Integer for Ipv6Addr
Source§fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
Computes the inclusive end of a range starting at self with length b,
by returning self + (b - 1).
§Panics
In debug builds, panics if b is zero or too large to compute a valid result.
In release builds, this will either panic or wrap on overflow; the result may be meaningless,
but it is always defined and safe (never causes undefined behavior)
Source§fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Computes the inclusive start of a range ending at self with length b,
by returning self - (b - 1).
§Panics
In debug builds, panics if b is zero or too large to compute a valid result.
In release builds, this will either panic or wrap on overflow; the result may be meaningless,
but it is always defined and safe (never causes undefined behavior).