Expand description
A generic wrapper for non-negative floating point values.
Ensures that values are >= 0 and finite, providing safe construction methods and a convenient macro.
Supports any float type implementing num_traits::Float.
§Examples
use nonneg_float::{NonNegative, nonneg};
let zero = NonNegative::<f64>::zero();
let val = NonNegative::try_new(3.14).unwrap();
let macro_val = nonneg!(5.0f64).unwrap();
assert_eq!(zero.get(), 0.0);
assert_eq!(val.get(), 3.14);
assert_eq!(macro_val.get(), 5.0);Macros§
- nonneg
- Macro to create a
NonNegativevalue.
Structs§
- NonNegative
- Wrapper type guaranteeing a non-negative floating-point value.
Enums§
- NonNegative
Error - Error type returned when trying to create a
NonNegativefrom an invalid value.