Skip to content

Commit

Permalink
phone-number, scale-generator: use range::contains (#1036)
Browse files Browse the repository at this point in the history
I'm honestly not really convinced by the phone-number one but I guess
it's one fewer mention of number_len so it's fine.

https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
  • Loading branch information
petertseng authored Nov 21, 2020
1 parent 0b3a64e commit 9ad579f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions exercises/phone-number/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ pub fn number(user_number: &str) -> Option<String> {

let number_len = filtered_number.len();

if number_len < 10
|| number_len > 11
if !(10..=11).contains(&number_len)
|| (filtered_number.len() == 11 && !filtered_number.starts_with('1'))
{
return None;
Expand Down
2 changes: 1 addition & 1 deletion exercises/scale-generator/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub mod note {
let mut iter = lc.chars();

let mut note = match iter.next() {
Some(c) if 'a' <= c && 'g' >= c => Note {
Some(c) if ('a'..='g').contains(&c) => Note {
tonic: match c {
'a' => Root::A,
'b' => Root::B,
Expand Down

0 comments on commit 9ad579f

Please sign in to comment.