Skip to content

Commit

Permalink
Count characters in password example
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon01 committed Sep 5, 2023
1 parent 9baa851 commit 67aa633
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions examples/password.rs
Expand Up @@ -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")
Expand All @@ -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()
);
}
2 changes: 1 addition & 1 deletion src/prompts/password.rs
Expand Up @@ -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<String> {
self.interact_on(&Term::stderr())
Expand Down

0 comments on commit 67aa633

Please sign in to comment.