pub struct NonNegative;Expand description
Marker type enforcing that a value is non-negative (zero or greater).
Use this type with Constrained<T, NonNegative> to encode non-negativity
at the type level.
You can construct a value constrained to be non-negative using either the
generic Constrained::new method or the convenient NonNegative::new
associated function.
§Examples
use twine_core::constraint::{Constrained, NonNegative};
// Generic constructor:
let x = Constrained::<_, NonNegative>::new(5).unwrap();
assert_eq!(x.into_inner(), 5);
// Associated constructor:
let y = NonNegative::new(0.0).unwrap();
assert_eq!(y.into_inner(), 0.0);
// Error cases:
assert!(NonNegative::new(-7).is_err());
assert!(NonNegative::new(f64::NAN).is_err());Implementations§
Source§impl NonNegative
impl NonNegative
Sourcepub fn new<T: PartialOrd + Zero>(
value: T,
) -> Result<Constrained<T, NonNegative>, ConstraintError>
pub fn new<T: PartialOrd + Zero>( value: T, ) -> Result<Constrained<T, NonNegative>, ConstraintError>
Constructs a Constrained<T, NonNegative> if the value is non-negative.
§Errors
Returns an error if the value is negative or not a number (NaN).
Sourcepub fn zero<T: PartialOrd + Zero>() -> Constrained<T, NonNegative>
pub fn zero<T: PartialOrd + Zero>() -> Constrained<T, NonNegative>
Returns the additive identity (zero) as a non-negative constrained value.
This method is equivalent to Constrained::<T, NonNegative>::zero().
Trait Implementations§
Source§impl Clone for NonNegative
impl Clone for NonNegative
Source§fn clone(&self) -> NonNegative
fn clone(&self) -> NonNegative
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 NonNegative
impl<T: PartialOrd + Zero> Constraint<T> for NonNegative
Source§impl Debug for NonNegative
impl Debug for NonNegative
Source§impl PartialEq for NonNegative
impl PartialEq for NonNegative
impl Copy for NonNegative
impl Eq for NonNegative
impl StructuralPartialEq for NonNegative
Auto Trait Implementations§
impl Freeze for NonNegative
impl RefUnwindSafe for NonNegative
impl Send for NonNegative
impl Sync for NonNegative
impl Unpin for NonNegative
impl UnwindSafe for NonNegative
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.