Macro inquire::length[][src]

macro_rules! length {
    ($length : expr) => { ... };
    ($length : expr, $message : expr) => { ... };
}
Expand description

Built-in validator that checks whether the answer length is equal to the specified value.

Be careful when using this as a StringValidator. The len() method used in this validator is not the best tool for that. See this StackOverflow question

Arguments

  • $length - Expected length of the input.
  • $message - optional - Error message returned by the validator. Defaults to “The length of the response should be $length”

Examples

use inquire::{length, validator::StringValidator};

let validator: StringValidator = length!(3);
assert_eq!(Ok(()), validator("Yes"));
assert_eq!(Err(String::from("The length of the response should be 3")), validator("No"));

let validator: StringValidator = length!(3, "Three characters please.");
assert_eq!(Ok(()), validator("Yes"));
assert_eq!(Err(String::from("Three characters please.")), validator("No"));