pub struct UnitInterval(/* private fields */);Expand description
A finite value in the inclusive [0.0, 1.0] range.
Use this for confidence, normalized scores, prior weights, and thresholds.
Implementations§
Source§impl UnitInterval
impl UnitInterval
Sourcepub fn new(value: f64) -> Result<Self, UnitIntervalError>
pub fn new(value: f64) -> Result<Self, UnitIntervalError>
Create a validated unit interval.
Returns an error for NaN, infinity, or values outside [0.0, 1.0].
Sourcepub fn clamped(value: f64) -> Self
pub fn clamped(value: f64) -> Self
Create a unit interval by clamping finite input.
Non-finite values become 0.0.
Sourcepub fn saturating_add(self, delta: f64) -> Self
pub fn saturating_add(self, delta: f64) -> Self
Add a delta and clamp the result back into the valid range.
Sourcepub fn to_basis_points(self) -> u16
pub fn to_basis_points(self) -> u16
Convert to basis points, rounded to the nearest basis point.
Trait Implementations§
Source§impl Clone for UnitInterval
impl Clone for UnitInterval
Source§fn clone(&self) -> UnitInterval
fn clone(&self) -> UnitInterval
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnitInterval
impl Debug for UnitInterval
Source§impl Default for UnitInterval
impl Default for UnitInterval
Source§impl<'de> Deserialize<'de> for UnitInterval
impl<'de> Deserialize<'de> for UnitInterval
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<UnitInterval> for f64
impl From<UnitInterval> for f64
Source§fn from(value: UnitInterval) -> Self
fn from(value: UnitInterval) -> Self
Converts to this type from the input type.
Source§impl PartialEq for UnitInterval
impl PartialEq for UnitInterval
Source§fn eq(&self, other: &UnitInterval) -> bool
fn eq(&self, other: &UnitInterval) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for UnitInterval
impl PartialOrd for UnitInterval
Source§impl Serialize for UnitInterval
impl Serialize for UnitInterval
Source§impl TryFrom<f64> for UnitInterval
impl TryFrom<f64> for UnitInterval
impl Copy for UnitInterval
impl StructuralPartialEq for UnitInterval
Auto Trait Implementations§
impl Freeze for UnitInterval
impl RefUnwindSafe for UnitInterval
impl Send for UnitInterval
impl Sync for UnitInterval
impl Unpin for UnitInterval
impl UnsafeUnpin for UnitInterval
impl UnwindSafe for UnitInterval
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
Mutably borrows from an owned value. Read more