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