Skip to main content

Total

Struct Total 

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

Source

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

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

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

pub const fn new(x: T) -> Self

Creates a new Total from a primitive float. All values are legal.

§Examples
use range_set_blaze::TotalF64;

let _ = TotalF64::new(f64::INFINITY);
Source

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.

Source

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.

Source

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

pub fn after(self) -> Self

Returns the next float in total order.

§Examples
use range_set_blaze::TotalF64;

assert_eq!(TotalF64::new(42.0).after().before().into_inner(), 42.0);
§Panics

In debug builds, panics if self is the maximum value. In release builds, wraps around to the minimum value instead.

Source

pub fn before(self) -> Self

Returns the previous float in total order.

§Examples
use range_set_blaze::TotalF64;

assert_eq!(TotalF64::new(42.0).before().after().into_inner(), 42.0);
§Panics

In debug builds, panics if self is the minimum value. In release builds, wraps around to the maximum value instead.

Source

pub fn checked_after(self) -> Option<Self>

Returns the next float.

Returns None if self is the maximum value.

§Examples
use range_set_blaze::TotalF64;

let value = TotalF64::new(42.0);
assert_eq!(value.checked_after(), Some(value.after()));
let value = TotalF64::MAX;
assert_eq!(value.checked_after(), None);
Source

pub fn checked_before(self) -> Option<Self>

Returns the previous float.

Returns None if self is the minimum value.

§Examples
use range_set_blaze::TotalF64;

let value = TotalF64::new(42.0);
assert_eq!(value.checked_before(), Some(value.before()));
let value = TotalF64::MIN;
assert_eq!(value.checked_before(), None);
Source

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

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

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

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§

Source§

impl<T: Clone + TotalFloat> Clone for Total<T>

Source§

fn clone(&self) -> Total<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy + TotalFloat> Copy for Total<T>

Source§

impl<T: Debug + TotalFloat> Debug for Total<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + TotalFloat> Default for Total<T>

Source§

fn default() -> Total<T>

Returns the “default value” for a type. Read more
Source§

impl<T: TotalFloat> Eq for Total<T>

Source§

impl<T: TotalFloat> Hash for Total<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: TotalFloat> Integer for Total<T>

Source§

type SafeLen = <T as TotalFloat>::SafeLen

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>. Read more
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. Read more
Source§

fn sub_one(self) -> Self

Subtracts one from the current value, panicking in debug mode if the operation underflows. Read more
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. Read more
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. Read more
Source§

fn min_value() -> Self

Returns the minimum value that can be represented by the type. Read more
Source§

fn max_value() -> Self

Returns the maximum value that can be represented by the type. Read more
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(r: &RangeInclusive<Self>) -> Self::SafeLen

Calculates the length of a range without overflow. Read more
Source§

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

Converts Integer::SafeLen to f64, potentially losing precision for large values.
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 inclusive_end_from_start(self, b: Self::SafeLen) -> Self

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

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

Computes self - (b - 1) where b is of type Integer::SafeLen. Read more
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. Read more
Source§

impl<T: TotalFloat> Ord for Total<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: TotalFloat> PartialEq for Total<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: TotalFloat> PartialOrd for Total<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V