Skip to content

Validator type doesn't allow capture of external variables #29

Description

@wellcaffeinated

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>;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions