Keats / validator

Simple validation for Rust structs
MIT License
2.07k stars 151 forks source link

Generalizing Option Macro Behaviour to OptionalValue Trait ? #322

Open PranavKumar-15032001 opened 7 months ago

PranavKumar-15032001 commented 7 months ago

We had a specific use-case, where for YAML parsing we have a custom type namely "Nullable" as the following structure:

pub enum Nullable<T> {
    /// Null value
    Null,
    /// Value is present
    Present(T),
}

This type behaves similar to Option type. Should we move towards generalizing the behaviour of the option type to any type that implements OptionalValue trait, which will define how to extract nested value for any type T.

trait OptionalValue {
    type Value;
    fn extract(&self) -> Option<Self::Value>;
}

?

Keats commented 7 months ago

I don't think it would be used enough to warrant adding it