mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 23:04:17 -05: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:
commit
3afa96bed4
1 changed files with 4 additions and 2 deletions
|
@ -13,7 +13,7 @@ fn byte_counter<T>(arg: T) -> usize {
|
||||||
// Obtain the number of characters (not bytes) in the given argument
|
// Obtain the number of characters (not bytes) in the given argument
|
||||||
// Add the AsRef trait appropriately as a trait bound
|
// Add the AsRef trait appropriately as a trait bound
|
||||||
fn char_counter<T>(arg: T) -> usize {
|
fn char_counter<T>(arg: T) -> usize {
|
||||||
arg.as_ref().chars().collect::<Vec<_>>().len()
|
arg.as_ref().chars().count()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -31,6 +31,8 @@ mod tests {
|
||||||
let s = "Café au lait";
|
let s = "Café au lait";
|
||||||
assert_ne!(char_counter(s), byte_counter(s));
|
assert_ne!(char_counter(s), byte_counter(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn same_counts() {
|
fn same_counts() {
|
||||||
let s = "Cafe au lait";
|
let s = "Cafe au lait";
|
||||||
assert_eq!(char_counter(s), byte_counter(s));
|
assert_eq!(char_counter(s), byte_counter(s));
|
||||||
|
|
Loading…
Reference in a new issue