pub struct Total<T: TotalFloat>(/* private fields */);Expand description
Experimental: A transparent wrapper around floating point values with total ordering.
Comparison, equality, and hashing all agree with total_cmp.
§Enabling
This type is experimental and must be enabled with the float_experimental feature.
cargo add range-set-blaze --features "float_experimental"That provides the TotalF32 and TotalF64 types.
If you’re building with nightly, you can instead use the float_nightly_experimental feature.
cargo add range-set-blaze --features "float_nightly_experimental"To also use the TotalF16 and TotalF128 types.
Implementations§
Source§impl<T: TotalFloat> Total<T>
impl<T: TotalFloat> Total<T>
Sourcepub const MIN: Self
pub const MIN: Self
The minimum value that can be represented by the type.
I.e., the smallest possible value according to total_cmp
Maps directly to crate::Integer::min_value()
§Examples
use range_set_blaze::TotalF64;
assert_eq!(TotalF64::MIN, TotalF64::new(f64::from_bits(u64::MAX)));Sourcepub const MAX: Self
pub const MAX: Self
The maximum value that can be represented by the type.
I.e., the largest possible value according to total_cmp
Maps directly to crate::Integer::max_value()
§Examples
use range_set_blaze::TotalF64;
assert_eq!(TotalF64::MAX, TotalF64::new(f64::from_bits(0x7fff_ffff_ffff_ffff)));Sourcepub const MAX_SIZE: T::SafeLen = T::MAX_SIZE
pub const MAX_SIZE: T::SafeLen = T::MAX_SIZE
The maximum possible size of a range, i.e. the size if [MIN..=MAX]
§Examples
use range_set_blaze::TotalF32;
assert_eq!(TotalF32::MAX_SIZE, u32::MAX as i64 + 1);Sourcepub fn inclusive_end_from_start(self, b: T::SafeLen) -> Self
pub fn inclusive_end_from_start(self, b: T::SafeLen) -> Self
Computes self + (b - 1) where b is of type SafeLen.
§Precondition
b must be small enough that the result stays within range for T. This is
checked with debug_assert! and is not checked in release builds, where
violating it produces an unspecified (nonsense, but not unsafe) result rather
than a panic. Callers are expected to only ever pass a b that satisfies this.
Sourcepub fn start_from_inclusive_end(self, b: T::SafeLen) -> Self
pub fn start_from_inclusive_end(self, b: T::SafeLen) -> Self
Computes self - (b - 1) where b is of type SafeLen.
§Precondition
b must be small enough that the result stays within range for T. This is
checked with debug_assert! and is not checked in release builds, where
violating it produces an unspecified (nonsense, but not unsafe) result rather
than a panic. Callers are expected to only ever pass a b that satisfies this.
Sourcepub const fn into_inner(self) -> T
pub const fn into_inner(self) -> T
Returns the wrapped value.
§Examples
use range_set_blaze::TotalF64;
assert_eq!(TotalF64::new(42.0).into_inner(), 42.0);Sourcepub fn checked_after(self) -> Option<Self>
pub fn checked_after(self) -> Option<Self>
Sourcepub fn checked_before(self) -> Option<Self>
pub fn checked_before(self) -> Option<Self>
Sourcepub fn from_primitive_range(range: RangeInclusive<T>) -> RangeInclusive<Self>
pub fn from_primitive_range(range: RangeInclusive<T>) -> RangeInclusive<Self>
Converts an inclusive primitive range into an inclusive Total range.
“Primitive” here means Rust’s built-in float type (e.g. f64).
§Examples
use range_set_blaze::{RangeSetBlaze, TotalF64};
let short = RangeSetBlaze::from(TotalF64::from_primitive_range(3.0..=5.0));
let long = RangeSetBlaze::from(TotalF64::new(3.0)..=TotalF64::new(5.0));
assert_eq!(short, long);Sourcepub fn from_primitive_ranges<I>(
ranges: I,
) -> impl Iterator<Item = RangeInclusive<Self>>where
I: IntoIterator<Item = RangeInclusive<T>>,
pub fn from_primitive_ranges<I>(
ranges: I,
) -> impl Iterator<Item = RangeInclusive<Self>>where
I: IntoIterator<Item = RangeInclusive<T>>,
Converts inclusive primitive ranges into inclusive Total ranges.
“Primitive” here means Rust’s built-in float type (e.g. f64).
§Examples
use range_set_blaze::{RangeSetBlaze, TotalF64};
let short = RangeSetBlaze::from_iter(TotalF64::from_primitive_ranges([1.0..=2.0, 3.0..=4.0]));
let long = RangeSetBlaze::from_iter([TotalF64::new(1.0)..=TotalF64::new(2.0), TotalF64::new(3.0)..=TotalF64::new(4.0)]);
assert_eq!(short, long);Sourcepub fn values<I>(values: I) -> impl Iterator<Item = Self>where
I: IntoIterator<Item = T>,
pub fn values<I>(values: I) -> impl Iterator<Item = Self>where
I: IntoIterator<Item = T>,
Convenience method to convert primitive values into ordered Total values.
§Examples
use range_set_blaze::{RangeSetBlaze, TotalF64};
let short = RangeSetBlaze::from_iter(TotalF64::values([1.0, 2.0, 3.0, 4.0]));
let long = RangeSetBlaze::from_iter([TotalF64::new(1.0), TotalF64::new(2.0), TotalF64::new(3.0), TotalF64::new(4.0)]);
assert_eq!(short, long);Sourcepub const fn from_primitive_slice(values: &[T]) -> &[Self]
pub const fn from_primitive_slice(values: &[T]) -> &[Self]
Views primitive values as ordered Total values.
“Primitive” here means Rust’s built-in float type (e.g. f64).
This runs in O(1) and does not allocate.
§Examples
use range_set_blaze::{RangeSetBlaze, TotalF64};
let short = RangeSetBlaze::from_iter(TotalF64::from_primitive_slice(&[1.0, 2.0, 3.0, 4.0]));
let long = RangeSetBlaze::from_iter([TotalF64::new(1.0), TotalF64::new(2.0), TotalF64::new(3.0), TotalF64::new(4.0)]);
assert_eq!(short, long);Trait Implementations§
impl<T: Copy + TotalFloat> Copy for Total<T>
impl<T: TotalFloat> Eq for Total<T>
Source§impl<T: TotalFloat> Integer for Total<T>
impl<T: TotalFloat> Integer for Total<T>
Source§type SafeLen = <T as TotalFloat>::SafeLen
type SafeLen = <T as TotalFloat>::SafeLen
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>. Read moreSource§fn checked_add_one(self) -> Option<Self>
fn checked_add_one(self) -> Option<Self>
None if the operation would overflow.Source§fn add_one(self) -> Self
fn add_one(self) -> Self
Source§fn sub_one(self) -> Self
fn sub_one(self) -> Self
Source§fn assign_sub_one(&mut self)
fn assign_sub_one(&mut self)
self.Source§fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next(range: &mut RangeInclusive<Self>) -> Option<Self>
None if the range is exhausted. Read moreSource§fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
fn range_next_back(range: &mut RangeInclusive<Self>) -> Option<Self>
None if the range is exhausted. Read moreSource§fn min_value() -> Self
fn min_value() -> Self
Source§fn max_value() -> Self
fn max_value() -> Self
Source§fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
fn from_slice(slice: impl AsRef<[Self]>) -> RangeSetBlaze<Self>
RangeSetBlaze from a slice, specific to the integer type.Source§fn safe_len(r: &RangeInclusive<Self>) -> Self::SafeLen
fn safe_len(r: &RangeInclusive<Self>) -> Self::SafeLen
Source§fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
fn safe_len_to_f64_lossy(len: Self::SafeLen) -> f64
Integer::SafeLen to f64, potentially losing precision for large values.Source§fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
fn f64_to_safe_len_lossy(f: f64) -> Self::SafeLen
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 inclusive_end_from_start(self, b: Self::SafeLen) -> Self
fn inclusive_end_from_start(self, b: Self::SafeLen) -> Self
Source§fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
fn start_from_inclusive_end(self, b: Self::SafeLen) -> Self
Source§fn exhausted_range() -> RangeInclusive<Self>
fn exhausted_range() -> RangeInclusive<Self>
Source§impl<T: TotalFloat> Ord for Total<T>
impl<T: TotalFloat> Ord for Total<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: TotalFloat> PartialOrd for Total<T>
impl<T: TotalFloat> PartialOrd for Total<T>
Auto Trait Implementations§
impl<T> Freeze for Total<T>where
T: Freeze,
impl<T> RefUnwindSafe for Total<T>where
T: RefUnwindSafe,
impl<T> Send for Total<T>
impl<T> Sync for Total<T>
impl<T> Unpin for Total<T>where
T: Unpin,
impl<T> UnsafeUnpin for Total<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Total<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more