Release notes: Release Nutype 0.4.2 · greyblake/nutype · GitHub
Nutype is a proc macro that allows adding extra constraints like sanitization and validation to the regular newtype pattern.
In this particular release support for derive of Arbitrary
trait is added, what facilitates property-based testing and fuzzing.
use nutype::nutype;
use arbtest::arbtest;
use arbitrary::Arbitrary;
#[nutype(
derive(Arbitrary, AsRef),
validate(
finite,
greater_or_equal = -1.0,
less_or_equal = 1.0,
),
)]
pub struct PearsonCorrelation(f64);
fn main() {
arbtest(|u| {
// Arbitrary generates only valid values of PearsonCorrelation
let correlation = PearsonCorrelation::arbitrary(u)?;
assert!(correlation.as_ref().is_finite());
assert!(*correlation.as_ref() >= -1.0);
assert!(*correlation.as_ref() <= 1.0);
Ok(())
});
}