Macro inquire::min_length
source · macro_rules! min_length { ($length:expr) => { ... }; ($length:expr, $message:expr) => { ... }; }
Expand description
Shorthand for the built-in MinLengthValidator
that checks whether the answer length is
larger than or equal to the specified threshold.
Arguments
$length
- Minimum length of the input.$message
- optional - Error message returned by the validator. Defaults to “The length of the response should be at least $length”
Examples
use inquire::{min_length, validator::{StringValidator, Validation}};
let validator = min_length!(3);
assert_eq!(Validation::Valid, validator.validate("Yes")?);
assert_eq!(Validation::Invalid("The length of the response should be at least 3".into()), validator.validate("No")?);
let validator = min_length!(3, "You have to give me more than that!");
assert_eq!(Validation::Valid, validator.validate("Yes")?);
assert_eq!(Validation::Invalid("You have to give me more than that!".into()), validator.validate("No")?);