-
Notifications
You must be signed in to change notification settings - Fork 158
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
Support enum #77
Comments
Not currently, this seems like a significant amount of work and I won't have the time/will to do it myself. If someone manages to add it though, it seems like a good feature.
and put the validation on the structs. |
Just a note for people finding this. While enums aren't supported for proc macros at the moment, if the issue you are trying to solve is just allowing traversal of enums with the nesting #[derive(Debug, Serialize, Deserialize)]
pub enum TargetType {
CircleTarget(CircleTarget),
PolygonTarget(PolygonTarget),
AlertTarget(AlertTarget),
}
impl Validate for TargetType {
#[allow(unused_mut)]
fn validate(&self) -> ::std::result::Result<(), ::validator::ValidationErrors> {
let mut errors = ::validator::ValidationErrors::new();
let mut result = if errors.is_empty() {
::std::result::Result::Ok(())
} else {
::std::result::Result::Err(errors)
};
match self {
TargetType::CircleTarget(t) => {
::validator::ValidationErrors::merge(result, "CircleTarget", t.validate())
}
TargetType::PolygonTarget(t) => {
::validator::ValidationErrors::merge(result, "PolygonTarget", t.validate())
}
_ => result,
}
}
} Then you put the |
I'm having the issue that it does not validate the field that is an enum with |
The proc macro has been rewritten, it should be easier to add support for enums if someone wants to. |
Hi,
I would like to validate enums, for example
Is this possible?
The text was updated successfully, but these errors were encountered: