Nutype 0.4.2 is released!

50 points greyblake

Nutype 0.4.2 - release notes

Nutype is a proc macro that allows adding extra constraints like sanitization and validation to the regular newtype pattern.

The new version support derives of Arbitrary respecting the validation rules.
Example:

#[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(())
    });
}