macro_rules! method_validator {
($(#[$meta:meta])* $fn_name:ident, $method:ident, $code:literal, $message:literal) => { ... };
($(#[$meta:meta])* $fn_name:ident, $method:ident, $code:literal) => { ... };
($(#[$meta:meta])* $fn_name:ident, $code:literal, $message:literal) => { ... };
($(#[$meta:meta])* $fn_name:ident, $code:literal) => { ... };
}Expand description
Generate a validator function that delegates to a method on the input value
Creates a public function fn(value: &str) -> Result<(), ValidationError> that
calls the given method on the input and validates the boolean result.
§Syntax
ⓘ
// Full form: separate function name, method name, error code, and message
method_validator!(
/// Doc comment
function_name,
method_name,
"error_code",
"Error message"
);
// Without message: generates "Provide a valid {code}"
method_validator!(
/// Doc comment
function_name,
method_name,
"error_code"
);
// Shorthand with message: uses function name as method name
method_validator!(
/// Doc comment
function_name,
"error_code",
"Error message"
);
// Minimal: uses function name as method name, generates default message
method_validator!(
/// Doc comment
function_name,
"error_code"
);