Skip to content

Commit 4b92988

Browse files
committed
Replace &str in with &String
This change keeps consistency with `Input`'s validation process. #219 (comment)
1 parent c3774c0 commit 4b92988

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

examples/password.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44
let password = Password::with_theme(&ColorfulTheme::default())
55
.with_prompt("Password")
66
.with_confirmation("Repeat password", "Error: the passwords don't match.")
7-
.validate_with(|input: &str| -> Result<(), &str> {
7+
.validate_with(|input: &String| -> Result<(), &str> {
88
if input.len() > 3 {
99
Ok(())
1010
} else {

src/prompts/password.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
use console::Term;
99
use zeroize::Zeroizing;
1010

11-
type PasswordValidatorCallback<'a> = Box<dyn Fn(&str) -> Option<String> + 'a>;
11+
type PasswordValidatorCallback<'a> = Box<dyn Fn(&String) -> Option<String> + 'a>;
1212

1313
/// Renders a password input prompt.
1414
///
@@ -87,7 +87,7 @@ impl<'a> Password<'a> {
8787
/// # use dialoguer::Password;
8888
/// let password: String = Password::new()
8989
/// .with_prompt("Enter password")
90-
/// .validate_with(|input: &str| -> Result<(), &str> {
90+
/// .validate_with(|input: &String| -> Result<(), &str> {
9191
/// if input.len() > 8 {
9292
/// Ok(())
9393
/// } else {
@@ -104,7 +104,7 @@ impl<'a> Password<'a> {
104104
{
105105
let old_validator_func = self.validator.take();
106106

107-
self.validator = Some(Box::new(move |value: &str| -> Option<String> {
107+
self.validator = Some(Box::new(move |value: &String| -> Option<String> {
108108
if let Some(old) = &old_validator_func {
109109
if let Some(err) = old(value) {
110110
return Some(err);

src/validate.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@ where
2626
}
2727

2828
/// Trait for password validators.
29+
#[allow(clippy::ptr_arg)]
2930
pub trait PasswordValidator {
3031
type Err;
3132

3233
/// Invoked with the value to validate.
3334
///
3435
/// If this produces `Ok(())` then the value is used and parsed, if
3536
/// an error is returned validation fails with that error.
36-
fn validate(&self, input: &str) -> Result<(), Self::Err>;
37+
fn validate(&self, input: &String) -> Result<(), Self::Err>;
3738
}
3839

3940
impl<F, E> PasswordValidator for F
4041
where
41-
F: Fn(&str) -> Result<(), E>,
42+
F: Fn(&String) -> Result<(), E>,
4243
{
4344
type Err = E;
4445

45-
fn validate(&self, input: &str) -> Result<(), Self::Err> {
46+
fn validate(&self, input: &String) -> Result<(), Self::Err> {
4647
self(input)
4748
}
4849
}

0 commit comments

Comments
 (0)