Skip to content

Commit

Permalink
Count characters in password example instead of bytes (#276)
Browse files Browse the repository at this point in the history
* Count characters in `password` example

* Fix password example too
  • Loading branch information
Gordon01 authored Sep 6, 2023
1 parent 9baa851 commit af5f522
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions examples/password.rs
Original file line number Diff line number Diff line change
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()
);
}
4 changes: 2 additions & 2 deletions src/prompts/password.rs
Original file line number Diff line number Diff line change
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 Expand Up @@ -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")
Expand Down

0 comments on commit af5f522

Please sign in to comment.