Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Easyoakland committed Feb 23, 2024
1 parent 2de4dfb commit 9cb5eed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions examples/fizzbuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ fn line_ending(tokens: &mut impl Tokens<Item = u8>) -> Option<&'static str> {
enum FizzBuzz {
Fizz,
Buzz,
FizzBuzz,
Both,
Neither,
}

/// Converts number to appropriate fizzbuzz type.
fn fizzbuzz(x: u32) -> FizzBuzz {
if x % 5 == 0 && x % 3 == 0 {
FizzBuzz::FizzBuzz
FizzBuzz::Both
} else if x % 3 == 0 {
FizzBuzz::Fizz
} else if x % 5 == 0 {
Expand Down Expand Up @@ -58,7 +58,7 @@ if it is divisible by five I'll say \"buzz\", and if it is divisible by both 3 a
.sep_by(
|t| {
Some(
t.take_while(|x| x.is_ascii_digit())
t.take_while(u8::is_ascii_digit)
.into_iter()
.map(|x| x as char)
.collect::<String>()
Expand All @@ -72,8 +72,8 @@ if it is divisible by five I'll say \"buzz\", and if it is divisible by both 3 a
match num {
Ok(x) => {
let res = fizzbuzz(x);
println!("{:?}", res);
parsed_result.push(res)
println!("{res:?}");
parsed_result.push(res);
}
Err(_) => println!("Ending parse on invalid u64"),
}
Expand Down
8 changes: 4 additions & 4 deletions src/stream_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait StreamTokensBuffer<Item>: Default {
impl<Item: core::clone::Clone> StreamTokensBuffer<Item> for VecDeque<Item> {
fn drain_front(&mut self, n: usize) {
if n >= self.len() {
self.clear()
self.clear();
} else {
// TODO test this vs self.drain(..n) performance
for _ in 0..n {
Expand All @@ -31,7 +31,7 @@ impl<Item: core::clone::Clone> StreamTokensBuffer<Item> for VecDeque<Item> {
}

fn push(&mut self, item: Item) {
self.push_back(item)
self.push_back(item);
}

fn get(&self, idx: usize) -> Option<Item> {
Expand Down Expand Up @@ -267,7 +267,7 @@ mod tests {
tokens.set_location(loc);
assert!(tokens.tokens("hello \n\t world".chars()));

assert_eq!(None, tokens.next())
assert_eq!(None, tokens.next());
}

#[test]
Expand All @@ -290,6 +290,6 @@ mod tests {
tokens.set_location(loc);
assert!(tokens.tokens("hello \n\t world".chars()));

assert_eq!(None, tokens.next())
assert_eq!(None, tokens.next());
}
}
8 changes: 4 additions & 4 deletions src/stream_tokens/str_stream_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub struct StrStreamTokens<
impl StreamTokensBuffer<char> for String {
fn drain_front(&mut self, n: usize) {
if n >= self.len() {
self.clear()
self.clear();
} else {
self.drain(..n).for_each(drop);
}
}

fn push(&mut self, item: char) {
self.push(item)
self.push(item);
}

fn get(&self, idx: usize) -> Option<char> {
Expand Down Expand Up @@ -80,7 +80,7 @@ where
}

fn set_location(&mut self, location: Self::Location) {
self.0.set_location(location)
self.0.set_location(location);
}

fn is_at_location(&self, location: &Self::Location) -> bool {
Expand All @@ -99,7 +99,7 @@ where
let res = self.0.buffer.elements[from.cursor - self.0.buffer.oldest_elem_cursor..].parse();
// Reset location on error.
if res.is_err() {
self.set_location(from)
self.set_location(from);
};
res
}
Expand Down

0 comments on commit 9cb5eed

Please sign in to comment.