From af5f522895377ffb58757550f297f14d14db4d99 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 6 Sep 2023 18:43:09 +0400 Subject: [PATCH] Count characters in `password` example instead of bytes (#276) * Count characters in `password` example * Fix password example too --- examples/password.rs | 7 +++++-- src/prompts/password.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/password.rs b/examples/password.rs index d85df1b3..ed8e4edb 100644 --- a/examples/password.rs +++ b/examples/password.rs @@ -5,7 +5,7 @@ fn main() { .with_prompt("Password") .with_confirmation("Repeat password", "Error: the passwords don't match.") .validate_with(|input: &String| -> Result<(), &str> { - if input.len() > 3 { + if input.chars().count() > 3 { Ok(()) } else { Err("Password must be longer than 3") @@ -14,5 +14,8 @@ fn main() { .interact() .unwrap(); - println!("Your password is {} characters long", password.len()); + println!( + "Your password is {} characters long", + password.chars().count() + ); } diff --git a/src/prompts/password.rs b/src/prompts/password.rs index 3893a446..39d46f07 100644 --- a/src/prompts/password.rs +++ b/src/prompts/password.rs @@ -86,7 +86,7 @@ impl Password<'_> { /// Enables user interaction and returns the result. /// - /// If the user confirms the result is `true`, `false` otherwise. + /// If the user confirms the result is `Ok()`, `Err()` otherwise. /// The dialog is rendered on stderr. pub fn interact(self) -> Result { self.interact_on(&Term::stderr()) @@ -159,7 +159,7 @@ impl<'a> Password<'a> { /// let password: String = Password::new() /// .with_prompt("Enter password") /// .validate_with(|input: &String| -> Result<(), &str> { - /// if input.len() > 8 { + /// if input.chars().count() > 8 { /// Ok(()) /// } else { /// Err("Password must be longer than 8")