We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Let's say you have the following context:
struct ValidatorContext { allow_non_ascii: bool }
In this case you want to apply the ascii rule conditionally on a field.
ascii
Right now you'd have to write a function like this:
fn conditional_ascii_check(value: &str, ctx: &ValidatorContext) -> garde::Result { if ctx.allow_non_ascii { return Ok(()); } garde::rules::ascii::apply(&value, ()) }
It would be interesting to have something like a #[garde(if)] statement.
#[garde(if)]
Example:
struct ValidatorContext { allow_non_ascii: bool } #[derive(Validate)] #[garde(context(ValidatorContext as ctx))] pub struct Data { #[garde(if(!ctx.allow_non_ascii, ascii))] text: String, }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Let's say you have the following context:
In this case you want to apply the
ascii
rule conditionally on a field.Right now you'd have to write a function like this:
It would be interesting to have something like a
#[garde(if)]
statement.Example:
The text was updated successfully, but these errors were encountered: