Keats / validator

Simple validation for Rust structs
MIT License
1.91k stars 140 forks source link

Question: ValidateRange - programmatic inspect range #305

Open ryanolson opened 4 months ago

ryanolson commented 4 months ago

Let's say I have two objects each with a different range:

struct InputA {
    #[validate(range(min = 0, max = 1))]
    pub val: f32
}

struct InputB {
    #[validate(range(min = 1, max = 2))]
    pub val: f32
}

And now I want to convert InputA to InputB by mapping the val in the range of A to the range of B with a simple linear transformation.

Is it possible to use a From trait which can access the ranges on each val to perform the transformation?

Keats commented 4 months ago

Nope, you can't access the validation rules programmatically currently