Macro inquire::max_length[][src]

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

Built-in validator that checks whether the answer length is smaller than or equal to the specified threshold.

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 - Maximum length of the input.
  • $message - optional - Error message returned by the validator. Defaults to “The length of the response should be at most $length”

Examples

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

let validator: StringValidator = max_length!(5);
assert_eq!(Ok(()), validator("Good"));
assert_eq!(Err(String::from("The length of the response should be at most 5")), validator("Terrible"));

let validator: StringValidator = max_length!(5, "Not too large!");
assert_eq!(Ok(()), validator("Good"));
assert_eq!(Err(String::from("Not too large!")), validator("Terrible"));