pub struct UnitIntervalLowerOpen;Expand description
Marker type enforcing that a value lies in the left-open unit interval: 0 < x ≤ 1.
Requires T: UnitBounds.
We provide UnitBounds implementations for f32, f64, and uom::si::f64::Ratio.
You can construct a value constrained to (0, 1] using either the generic
Constrained::new method or the convenient UnitIntervalLowerOpen::new
associated function.
§Examples
Using with f64:
use twine_models::support::constraint::{Constrained, UnitIntervalLowerOpen};
// Generic constructor:
let a = Constrained::<_, UnitIntervalLowerOpen>::new(0.25).unwrap();
assert_eq!(a.into_inner(), 0.25);
// Associated constructor:
let b = UnitIntervalLowerOpen::new(1.0).unwrap();
assert_eq!(b.as_ref(), &1.0);
// Endpoint:
let o = UnitIntervalLowerOpen::one::<f64>();
assert_eq!(o.into_inner(), 1.0);
// Error cases:
assert!(UnitIntervalLowerOpen::new(0.0).is_err());
assert!(UnitIntervalLowerOpen::new(-0.5).is_err());
assert!(UnitIntervalLowerOpen::new(f64::NAN).is_err());Using with uom::si::f64::Ratio:
use twine_models::support::constraint::{Constrained, UnitIntervalLowerOpen};
use uom::si::{f64::Ratio, ratio::{ratio, percent}};
let r = Constrained::<Ratio, UnitIntervalLowerOpen>::new(Ratio::new::<ratio>(0.42)).unwrap();
assert_eq!(r.as_ref().get::<percent>(), 42.0);
let o = UnitIntervalLowerOpen::one::<Ratio>();
assert_eq!(o.into_inner().get::<percent>(), 100.0);Implementations§
Source§impl UnitIntervalLowerOpen
impl UnitIntervalLowerOpen
Sourcepub fn new<T: UnitBounds>(
value: T,
) -> Result<Constrained<T, UnitIntervalLowerOpen>, ConstraintError>
pub fn new<T: UnitBounds>( value: T, ) -> Result<Constrained<T, UnitIntervalLowerOpen>, ConstraintError>
Constructs Constrained<T, UnitIntervalLowerOpen> if 0 < value ≤ 1.
§Errors
Fails if the value is outside the lower-open unit interval:
ConstraintError::BelowMinimumif less than or equal to zero.ConstraintError::AboveMaximumif greater than one.ConstraintError::NotANumberif comparison is undefined (e.g., NaN).
Sourcepub fn one<T: UnitBounds>() -> Constrained<T, UnitIntervalLowerOpen>
pub fn one<T: UnitBounds>() -> Constrained<T, UnitIntervalLowerOpen>
Returns the upper bound (one) as a constrained value.
Trait Implementations§
Source§impl Clone for UnitIntervalLowerOpen
impl Clone for UnitIntervalLowerOpen
Source§fn clone(&self) -> UnitIntervalLowerOpen
fn clone(&self) -> UnitIntervalLowerOpen
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: UnitBounds> Constraint<T> for UnitIntervalLowerOpen
impl<T: UnitBounds> Constraint<T> for UnitIntervalLowerOpen
Source§impl Debug for UnitIntervalLowerOpen
impl Debug for UnitIntervalLowerOpen
Source§impl Ord for UnitIntervalLowerOpen
impl Ord for UnitIntervalLowerOpen
Source§fn cmp(&self, other: &UnitIntervalLowerOpen) -> Ordering
fn cmp(&self, other: &UnitIntervalLowerOpen) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for UnitIntervalLowerOpen
impl PartialEq for UnitIntervalLowerOpen
Source§impl PartialOrd for UnitIntervalLowerOpen
impl PartialOrd for UnitIntervalLowerOpen
impl Copy for UnitIntervalLowerOpen
impl Eq for UnitIntervalLowerOpen
impl StructuralPartialEq for UnitIntervalLowerOpen
Auto Trait Implementations§
impl Freeze for UnitIntervalLowerOpen
impl RefUnwindSafe for UnitIntervalLowerOpen
impl Send for UnitIntervalLowerOpen
impl Sync for UnitIntervalLowerOpen
impl Unpin for UnitIntervalLowerOpen
impl UnsafeUnpin for UnitIntervalLowerOpen
impl UnwindSafe for UnitIntervalLowerOpen
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