pub struct StrictlyPositive;Expand description
Marker type enforcing that a value is strictly positive (greater than zero).
Use this type with Constrained<T, StrictlyPositive> to encode strict
positivity at the type level.
You can construct a value constrained to be strictly positive using
either the generic Constrained::new method or the convenient
StrictlyPositive::new associated function.
§Examples
use twine_core::constraint::{Constrained, StrictlyPositive};
// Generic constructor:
let x = Constrained::<_, StrictlyPositive>::new(1).unwrap();
assert_eq!(x.into_inner(), 1);
// Associated constructor:
let y = StrictlyPositive::new(3.14).unwrap();
assert_eq!(y.into_inner(), 3.14);
// Error cases:
assert!(StrictlyPositive::new(0).is_err());
assert!(StrictlyPositive::new(-1).is_err());
assert!(StrictlyPositive::new(f64::NAN).is_err());Implementations§
Source§impl StrictlyPositive
 
impl StrictlyPositive
Sourcepub fn new<T: PartialOrd + Zero>(
    value: T,
) -> Result<Constrained<T, StrictlyPositive>, ConstraintError>
 
pub fn new<T: PartialOrd + Zero>( value: T, ) -> Result<Constrained<T, StrictlyPositive>, ConstraintError>
Constructs a Constrained<T, StrictlyPositive> if the value is strictly positive.
§Errors
Returns an error if the value is zero, negative, or not a number (NaN).
Trait Implementations§
Source§impl Clone for StrictlyPositive
 
impl Clone for StrictlyPositive
Source§fn clone(&self) -> StrictlyPositive
 
fn clone(&self) -> StrictlyPositive
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: PartialOrd + Zero> Constraint<T> for StrictlyPositive
 
impl<T: PartialOrd + Zero> Constraint<T> for StrictlyPositive
Source§impl Debug for StrictlyPositive
 
impl Debug for StrictlyPositive
Source§impl PartialEq for StrictlyPositive
 
impl PartialEq for StrictlyPositive
impl Copy for StrictlyPositive
impl Eq for StrictlyPositive
impl StructuralPartialEq for StrictlyPositive
Auto Trait Implementations§
impl Freeze for StrictlyPositive
impl RefUnwindSafe for StrictlyPositive
impl Send for StrictlyPositive
impl Sync for StrictlyPositive
impl Unpin for StrictlyPositive
impl UnwindSafe for StrictlyPositive
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
Compare self to 
key and return true if they are equal.