[rust] Don't borrow inputs for day solvers

wip
Alpha Chen 9 years ago
parent bae1972faa
commit 3ebcf0fbeb

@ -1,6 +1,6 @@
use std::io; use std::io;
pub trait Day { pub trait Day {
fn new(&String) -> Self; fn new(String) -> Self;
fn solve(&self) -> io::Result<i32>; fn solve(&self) -> io::Result<i32>;
} }

@ -8,8 +8,8 @@ pub struct Day01 {
} }
impl Day for Day01 { impl Day for Day01 {
fn new(input: &String) -> Day01 { fn new(input: String) -> Day01 {
Day01 { input: input.clone() } Day01 { input: input }
} }
fn solve(&self) -> io::Result<i32> { fn solve(&self) -> io::Result<i32> {

@ -7,7 +7,7 @@ pub struct Day02 {
} }
impl Day for Day02 { impl Day for Day02 {
fn new(input: &String) -> Day02 { fn new(input: String) -> Day02 {
let presents = input.split("\n").map(|line| Present::new(line)); let presents = input.split("\n").map(|line| Present::new(line));
Day02 { presents: presents.collect::<Vec<Present>>() } Day02 { presents: presents.collect::<Vec<Present>>() }
} }

@ -12,8 +12,8 @@ pub struct Day03 {
} }
impl Day for Day03 { impl Day for Day03 {
fn new(input: &String) -> Day03 { fn new(input: String) -> Day03 {
Day03 { directions: input.clone() } Day03 { directions: input }
} }
fn solve(&self) -> io::Result<i32> { fn solve(&self) -> io::Result<i32> {

@ -20,6 +20,6 @@ fn read_input(filename: &str) -> Result<String, io::Error> {
fn main() { fn main() {
let input = read_input("day_03").unwrap(); let input = read_input("day_03").unwrap();
let day = Day03::new(&input); let day = Day03::new(input);
println!("{}", day.solve().unwrap()); println!("{}", day.solve().unwrap());
} }

Loading…
Cancel
Save