promkit icon indicating copy to clipboard operation
promkit copied to clipboard

Validator type doesn't allow capture of external variables

Open wellcaffeinated opened this issue 1 year ago • 1 comments

Since type Validator<T> = fn(&T) -> bool;, i can't do something like:

let existing_filenames = read_dir(...);

Readline::default()
    .title("Name new file:")
    .validator(|name| !existing_filenames.contains(name.to_string()), |name| format!("File {} already exists", name))
    .prompt()?
    .run()?;

Suggest swapping this to something like type Validator<T> = Box<dyn Fn(&T) -> bool>;

wellcaffeinated avatar Jun 27 '24 22:06 wellcaffeinated

Ran into this myself, this definitely limits the use-case of validators.

JeanMertz avatar Apr 15 '25 20:04 JeanMertz