Keats/validator

Generalizing Option Macro Behaviour to OptionalValue Trait ?

Opened this issue · 1 comments

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>;
}

?

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