diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/dialoguer/src/validate.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/dialoguer/src/validate.rs')
-rw-r--r-- | vendor/dialoguer/src/validate.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/dialoguer/src/validate.rs b/vendor/dialoguer/src/validate.rs new file mode 100644 index 0000000..addc9b4 --- /dev/null +++ b/vendor/dialoguer/src/validate.rs @@ -0,0 +1,49 @@ +//! Provides validation for text inputs + +/// Trait for input validators. +/// +/// A generic implementation for `Fn(&str) -> Result<(), E>` is provided +/// to facilitate development. +pub trait Validator<T> { + type Err; + + /// Invoked with the value to validate. + /// + /// If this produces `Ok(())` then the value is used and parsed, if + /// an error is returned validation fails with that error. + fn validate(&mut self, input: &T) -> Result<(), Self::Err>; +} + +impl<T, F, E> Validator<T> for F +where + F: FnMut(&T) -> Result<(), E>, +{ + type Err = E; + + fn validate(&mut self, input: &T) -> Result<(), Self::Err> { + self(input) + } +} + +/// Trait for password validators. +#[allow(clippy::ptr_arg)] +pub trait PasswordValidator { + type Err; + + /// Invoked with the value to validate. + /// + /// If this produces `Ok(())` then the value is used and parsed, if + /// an error is returned validation fails with that error. + fn validate(&self, input: &String) -> Result<(), Self::Err>; +} + +impl<F, E> PasswordValidator for F +where + F: Fn(&String) -> Result<(), E>, +{ + type Err = E; + + fn validate(&self, input: &String) -> Result<(), Self::Err> { + self(input) + } +} |