Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalizing Option Macro Behaviour to OptionalValue Trait ? #322

Open
PranavKumar-15032001 opened this issue Apr 15, 2024 · 1 comment
Open

Comments

@PranavKumar-15032001
Copy link

PranavKumar-15032001 commented Apr 15, 2024

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

?

@PranavKumar-15032001 PranavKumar-15032001 changed the title Generalizing Option Macro Behaviour to EnumValue Trait ? Generalizing Option Macro Behaviour to OptionalValue Trait ? Apr 15, 2024
@Keats
Copy link
Owner

Keats commented Apr 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants