From 683917dd7484e3e505deacbc0ff05f43e087cc2c Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 30 May 2023 12:34:43 -0700 Subject: [PATCH] Clear clippy warnings --- renrs-gui/src/lib.rs | 4 ++-- renrs/src/lib.rs | 16 +++++++++------- renrs/src/parser/block.rs | 6 +++--- renrs/src/parser/event.rs | 4 ++-- renrs/src/parser/utils.rs | 6 +++--- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/renrs-gui/src/lib.rs b/renrs-gui/src/lib.rs index 13d50ae..c41e8d3 100644 --- a/renrs-gui/src/lib.rs +++ b/renrs-gui/src/lib.rs @@ -163,10 +163,10 @@ impl App { } let Vector2f { x, y } = shape.position(); - if x >= WIDTH - SIZE || x < 0.0 { + if !(0.0..WIDTH - SIZE).contains(&x) { velocity.x *= -1.0; } - if y >= HEIGHT - SIZE || y < 0.0 { + if !(0.0..HEIGHT - SIZE).contains(&y) { velocity.y *= -1.0; } shape.set_position(Vector2f::new(x + velocity.x, y + velocity.y)); diff --git a/renrs/src/lib.rs b/renrs/src/lib.rs index 5be83e7..ffff5ec 100644 --- a/renrs/src/lib.rs +++ b/renrs/src/lib.rs @@ -18,17 +18,19 @@ impl State { } } - pub fn next(&mut self) -> Option { + fn next_command(&mut self) -> Option { + self.script.borrow_mut().next(&self.script) + } +} +impl Iterator for State { + type Item = Event; + fn next(&mut self) -> Option { while let Some(command) = self.next_command() { let event = command.execute(); - if let Some(_) = event { + if event.is_some() { return event; } } None } - - fn next_command(&mut self) -> Option { - self.script.borrow_mut().next(&self.script) - } -} +} \ No newline at end of file diff --git a/renrs/src/parser/block.rs b/renrs/src/parser/block.rs index 0f14df5..5dab512 100644 --- a/renrs/src/parser/block.rs +++ b/renrs/src/parser/block.rs @@ -78,7 +78,7 @@ impl CommandContext { } impl CommandBlock { - pub fn next<'a>(&mut self, self_rc: &Rc>) -> Option { + pub fn next(&mut self, self_rc: &Rc>) -> Option { let mut next = match self.next { Some(next) => next, None => return None, @@ -98,7 +98,7 @@ impl CommandBlock { next += 1; break; } - BlockElement::Block(block) => match block.borrow_mut().next(&block) { + BlockElement::Block(block) => match block.borrow_mut().next(block) { Some(context_command) => { result = Some(context_command); break; @@ -133,7 +133,7 @@ impl CommandBlock { pub fn get_root(&self, self_rc: &Rc>) -> Rc> { if let Some(parent) = &self.parent { - parent.borrow().get_root(&parent) + parent.borrow().get_root(parent) } else { self_rc.clone() } diff --git a/renrs/src/parser/event.rs b/renrs/src/parser/event.rs index b2344d9..5cfbf90 100644 --- a/renrs/src/parser/event.rs +++ b/renrs/src/parser/event.rs @@ -19,8 +19,8 @@ impl Event { let variables = context.get_variables(); *name = name .as_deref() - .map(|name| interpolate_string(&name, &variables)); - *text = interpolate_string(&text, &variables); + .map(|name| interpolate_string(name, &variables)); + *text = interpolate_string(text, &variables); } } self diff --git a/renrs/src/parser/utils.rs b/renrs/src/parser/utils.rs index 395257c..0f230d0 100644 --- a/renrs/src/parser/utils.rs +++ b/renrs/src/parser/utils.rs @@ -4,7 +4,7 @@ use super::{ }; pub fn parse_line(pair: Pair) -> Vec { - pair.into_inner().map(|pair| parse_token(pair)).collect() + pair.into_inner().map(parse_token).collect() } // Line description e.g. [String, Keyword, Array] @@ -12,10 +12,10 @@ pub fn parse_line(pair: Pair) -> Vec { pub fn describe_line(line: &[Token]) -> String { let mut description = "[".to_owned(); let mut iter = line.iter(); - description.push_str(&format!("{}", iter.next().unwrap().print())); + description.push_str(iter.next().unwrap().print()); for token in iter { description.push_str(&format!(", {}", token.print())); } - description.push_str("]"); + description.push(']'); description }