clippy + missing files

This commit is contained in:
kageru 2019-12-13 19:36:47 +01:00
parent 3f6ff50094
commit 875c0959a4
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 48 additions and 5 deletions

1
2019/13/input Normal file

File diff suppressed because one or more lines are too long

40
2019/13/src/tile.rs Normal file
View File

@ -0,0 +1,40 @@
use std::fmt::{Display, Error, Formatter};
pub enum Tile {
Empty,
Wall,
Block,
Paddle,
Ball,
}
impl Display for Tile {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
let c: char = self.into();
write!(fmt, "{}", c)
}
}
impl From<i64> for Tile {
fn from(num: i64) -> Self {
match num {
0 => Tile::Empty,
1 => Tile::Wall,
2 => Tile::Block,
3 => Tile::Paddle,
4 => Tile::Ball,
_ => unreachable!("Illegal tile ID"),
}
}
}
impl Into<char> for &Tile {
fn into(self) -> char {
match self {
Tile::Empty => ' ',
Tile::Wall => '█',
Tile::Block => '⌂',
Tile::Paddle => '_',
Tile::Ball => '•',
}
}
}

View File

@ -1,5 +1,7 @@
use itertools::join;
use std::collections::HashMap;
use std::fmt::Display;
use std::hash::BuildHasher;
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)]
pub struct Position2D {
@ -23,7 +25,7 @@ fn get_boundaries(input: &[&Position2D]) -> Boundaries {
Boundaries { x_min, x_max, y_min, y_max }
}
pub fn draw_ascii<T: std::fmt::Display>(coordinates: &HashMap<Position2D, T>, default: T) -> String {
pub fn draw_ascii<T: Display, S: BuildHasher>(coordinates: &HashMap<Position2D, T, S>, default: T) -> String {
let b = get_boundaries(&coordinates.keys().collect::<Vec<_>>());
join(
(b.y_min..=b.y_max).rev().map(|y| {

View File

@ -35,12 +35,12 @@ impl IntComputer {
pub fn step(&mut self) -> IntComputerResult {
match self.cmd_buffer.pop().unwrap_or_else(|| self.decode_next()) {
Operation::Halt {} => return IntComputerResult::Halt,
Operation::Halt {} => IntComputerResult::Halt,
op => {
if let Some(o) = self.execute(op.to_owned()) {
return IntComputerResult::Output(o);
if let Some(o) = self.execute(op) {
IntComputerResult::Output(o)
} else {
return IntComputerResult::Continue;
IntComputerResult::Continue
}
}
}