Clear clippy warnings

main
Elnu 2 years ago
parent c72bd94291
commit 683917dd74

@ -163,10 +163,10 @@ impl App {
} }
let Vector2f { x, y } = shape.position(); let Vector2f { x, y } = shape.position();
if x >= WIDTH - SIZE || x < 0.0 { if !(0.0..WIDTH - SIZE).contains(&x) {
velocity.x *= -1.0; velocity.x *= -1.0;
} }
if y >= HEIGHT - SIZE || y < 0.0 { if !(0.0..HEIGHT - SIZE).contains(&y) {
velocity.y *= -1.0; velocity.y *= -1.0;
} }
shape.set_position(Vector2f::new(x + velocity.x, y + velocity.y)); shape.set_position(Vector2f::new(x + velocity.x, y + velocity.y));

@ -18,17 +18,19 @@ impl State {
} }
} }
pub fn next(&mut self) -> Option<Event> { fn next_command(&mut self) -> Option<CommandContext> {
self.script.borrow_mut().next(&self.script)
}
}
impl Iterator for State {
type Item = Event;
fn next(&mut self) -> Option<Self::Item> {
while let Some(command) = self.next_command() { while let Some(command) = self.next_command() {
let event = command.execute(); let event = command.execute();
if let Some(_) = event { if event.is_some() {
return event; return event;
} }
} }
None None
} }
}
fn next_command(&mut self) -> Option<CommandContext> {
self.script.borrow_mut().next(&self.script)
}
}

@ -78,7 +78,7 @@ impl CommandContext {
} }
impl CommandBlock { impl CommandBlock {
pub fn next<'a>(&mut self, self_rc: &Rc<RefCell<Self>>) -> Option<CommandContext> { pub fn next(&mut self, self_rc: &Rc<RefCell<Self>>) -> Option<CommandContext> {
let mut next = match self.next { let mut next = match self.next {
Some(next) => next, Some(next) => next,
None => return None, None => return None,
@ -98,7 +98,7 @@ impl CommandBlock {
next += 1; next += 1;
break; break;
} }
BlockElement::Block(block) => match block.borrow_mut().next(&block) { BlockElement::Block(block) => match block.borrow_mut().next(block) {
Some(context_command) => { Some(context_command) => {
result = Some(context_command); result = Some(context_command);
break; break;
@ -133,7 +133,7 @@ impl CommandBlock {
pub fn get_root(&self, self_rc: &Rc<RefCell<Self>>) -> Rc<RefCell<Self>> { pub fn get_root(&self, self_rc: &Rc<RefCell<Self>>) -> Rc<RefCell<Self>> {
if let Some(parent) = &self.parent { if let Some(parent) = &self.parent {
parent.borrow().get_root(&parent) parent.borrow().get_root(parent)
} else { } else {
self_rc.clone() self_rc.clone()
} }

@ -19,8 +19,8 @@ impl Event {
let variables = context.get_variables(); let variables = context.get_variables();
*name = name *name = name
.as_deref() .as_deref()
.map(|name| interpolate_string(&name, &variables)); .map(|name| interpolate_string(name, &variables));
*text = interpolate_string(&text, &variables); *text = interpolate_string(text, &variables);
} }
} }
self self

@ -4,7 +4,7 @@ use super::{
}; };
pub fn parse_line(pair: Pair) -> Vec<Token> { pub fn parse_line(pair: Pair) -> Vec<Token> {
pair.into_inner().map(|pair| parse_token(pair)).collect() pair.into_inner().map(parse_token).collect()
} }
// Line description e.g. [String, Keyword, Array] // Line description e.g. [String, Keyword, Array]
@ -12,10 +12,10 @@ pub fn parse_line(pair: Pair) -> Vec<Token> {
pub fn describe_line(line: &[Token]) -> String { pub fn describe_line(line: &[Token]) -> String {
let mut description = "[".to_owned(); let mut description = "[".to_owned();
let mut iter = line.iter(); let mut iter = line.iter();
description.push_str(&format!("{}", iter.next().unwrap().print())); description.push_str(iter.next().unwrap().print());
for token in iter { for token in iter {
description.push_str(&format!(", {}", token.print())); description.push_str(&format!(", {}", token.print()));
} }
description.push_str("]"); description.push(']');
description description
} }

Loading…
Cancel
Save