1
0
Fork 0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-05-12 01:06:08 +02:00

Enable a test and improve per clippy's suggestion. (#256)

Enable a test and improve per clippy's suggestion.
This commit is contained in:
fmoko 2019-12-25 00:59:35 +01:00 committed by GitHub
commit 3afa96bed4
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,7 @@ fn byte_counter<T>(arg: T) -> usize {
// Obtain the number of characters (not bytes) in the given argument
// Add the AsRef trait appropriately as a trait bound
fn char_counter<T>(arg: T) -> usize {
arg.as_ref().chars().collect::<Vec<_>>().len()
arg.as_ref().chars().count()
}
fn main() {
@ -31,8 +31,10 @@ mod tests {
let s = "Café au lait";
assert_ne!(char_counter(s), byte_counter(s));
}
#[test]
fn same_counts() {
let s = "Cafe au lait";
assert_eq!(char_counter(s), byte_counter(s));
}
}
}