Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide as_string() method to return the alphabet characters #264

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/alphabet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ impl Alphabet {

Ok(Self::from_str_unchecked(alphabet))
}

/// Create a `&str` from the symbols in the `Alphabet`
pub fn as_str(&self) -> &str {
std::str::from_utf8(&self.symbols).unwrap()
JosiahParry marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl convert::TryFrom<&str> for Alphabet {
Expand Down Expand Up @@ -270,4 +275,11 @@ mod tests {
.unwrap()
);
}

#[test]
fn str_same_as_input() {
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
let a = Alphabet::try_from(alphabet).unwrap();
assert_eq!(alphabet, a.as_str())
}
}