Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wellcaffeinated opened this issue Jun 27, 2024 · 0 comments
Open

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

wellcaffeinated opened this issue Jun 27, 2024 · 0 comments

Comments

@wellcaffeinated
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant