Trait Integer

Source
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§

Source

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§

Source

fn checked_add_one(self) -> Option<Self>

Attempts to add one to the current value, returning None if the operation would overflow.

Source

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);
Source

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);
Source

fn assign_sub_one(&mut self)

Subtracts one from the current value and assigns it back to self.

Source

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.

Source

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.

Source

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);
Source

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);
Source

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Creates a RangeSetBlaze from a slice, specific to the integer type.

Source

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);
Source

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.

Source

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Converts Integer::SafeLen to f64, potentially losing precision for large values.

Source

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Computes self + (b - 1) where b is of type Integer::SafeLen.

Source

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Computes self - (b - 1) where b is of type Integer::SafeLen.

Provided Methods§

Source

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

Source§

type SafeLen = u32

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for i8

Source§

type SafeLen = u16

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for i16

Source§

type SafeLen = u32

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for i32

Source§

type SafeLen = u64

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for i64

Source§

type SafeLen = u128

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for i128

Source§

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

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).

Source§

type SafeLen = UIntPlusOne<u128>

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

impl Integer for isize

Source§

type SafeLen = u64

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for u8

Source§

type SafeLen = u16

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for u16

Source§

type SafeLen = u32

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for u32

Source§

type SafeLen = u64

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for u64

Source§

type SafeLen = u128

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for u128

Source§

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

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).

Source§

type SafeLen = UIntPlusOne<u128>

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

impl Integer for usize

Source§

type SafeLen = u64

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for Ipv4Addr

Source§

type SafeLen = u64

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Source§

fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self

Source§

fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self

Source§

impl Integer for Ipv6Addr

Source§

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

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).

Source§

type SafeLen = UIntPlusOne<u128>

Source§

fn checked_add_one(self) -> Option<Self>

Source§

fn add_one(self) -> Self

Source§

fn sub_one(self) -> Self

Source§

fn assign_sub_one(&mut self)

Source§

fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>

Source§

fn min_value() -> Self

Source§

fn max_value() -> Self

Source§

fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>

Source§

fn safe_len(r: &RangeInclusive<Self>) -> <Self as Integer>::SafeLen

Source§

fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64

Source§

fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen

Implementors§