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