Skip to content

Support for #[validate(one_of(...))] for simple enum-like validations #375

@jonjsmith

Description

@jonjsmith

I’d like to have support for a #[validate(one_of(...))] attribute to simplify enum-like validations. Right now, I believe this can only be done in a custom function. A built-in validator like the following would be much cleaner.

#[validate(one_of("pending", "completed", "failed"))]
status: String

Similar functionality exists in marshmallow validate.OneOf

I’m open to feedback on this, but I wanted to see if this is something that would be aligned with the goals of this crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions