use aoc crate for common stuff

This commit is contained in:
Antoine Martin 2019-12-01 22:22:12 +01:00
parent 907e883d48
commit 64410f0042
18 changed files with 49 additions and 28 deletions

13
Cargo.lock generated
View file

@ -1,14 +1,27 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "aoc"
version = "0.1.0"
[[package]] [[package]]
name = "aoc2015" name = "aoc2015"
version = "0.1.0" version = "0.1.0"
dependencies = [
"aoc 0.1.0",
]
[[package]] [[package]]
name = "aoc2018" name = "aoc2018"
version = "0.1.0" version = "0.1.0"
dependencies = [
"aoc 0.1.0",
]
[[package]] [[package]]
name = "aoc2019" name = "aoc2019"
version = "0.1.0" version = "0.1.0"
dependencies = [
"aoc 0.1.0",
]

View file

@ -1,5 +1,6 @@
[workspace] [workspace]
members = [ members = [
"aoc",
"aoc2015", "aoc2015",
"aoc2018", "aoc2018",
"aoc2019", "aoc2019",

9
aoc/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "aoc"
version = "0.1.0"
authors = ["Antoine Martin <antoine97.martin@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

6
aoc/src/lib.rs Normal file
View file

@ -0,0 +1,6 @@
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[macro_export]
macro_rules! err {
($($string:expr),+) => (Box::<dyn std::error::Error>::from(format!($($string),+)))
}

View file

@ -7,3 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
aoc = { path = "../aoc" }

View file

@ -1,5 +1,5 @@
use super::err; use aoc::err;
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day01.txt"); const INPUT: &str = include_str!("../input/day01.txt");

View file

@ -1,8 +1 @@
pub mod day01; pub mod day01;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[macro_export]
macro_rules! err {
($($string:expr),+) => (Box::<dyn std::error::Error>::from(format!($($string),+)))
}

View file

@ -1,8 +1,8 @@
use std::env; use std::env;
use aoc2015::day01; use aoc::Result;
use aoc2015::Result; use aoc2015::day01;
fn main() -> Result<()> { fn main() -> Result<()> {
let days: &[fn() -> Result<()>] = &[day01::run]; let days: &[fn() -> Result<()>] = &[day01::run];

View file

@ -7,3 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
aoc = { path = "../aoc" }

View file

@ -1,6 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day01.txt"); const INPUT: &str = include_str!("../input/day01.txt");

View file

@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day02.txt"); const INPUT: &str = include_str!("../input/day02.txt");

View file

@ -3,8 +3,8 @@ use std::collections::HashSet;
use std::error::Error; use std::error::Error;
use std::str::FromStr; use std::str::FromStr;
use super::err; use aoc::err;
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day03.txt"); const INPUT: &str = include_str!("../input/day03.txt");

View file

@ -2,8 +2,8 @@ use std::collections::HashMap;
use std::error::Error; use std::error::Error;
use std::str::FromStr; use std::str::FromStr;
use super::err; use aoc::err;
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day04.txt"); const INPUT: &str = include_str!("../input/day04.txt");

View file

@ -1,6 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day05.txt"); const INPUT: &str = include_str!("../input/day05.txt");

View file

@ -3,10 +3,3 @@ pub mod day02;
pub mod day03; pub mod day03;
pub mod day04; pub mod day04;
pub mod day05; pub mod day05;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[macro_export]
macro_rules! err {
($($string:expr),+) => (Box::<dyn std::error::Error>::from(format!($($string),+)))
}

View file

@ -1,13 +1,13 @@
use std::env; use std::env;
use aoc::Result;
use aoc2018::day01; use aoc2018::day01;
use aoc2018::day02; use aoc2018::day02;
use aoc2018::day03; use aoc2018::day03;
use aoc2018::day04; use aoc2018::day04;
use aoc2018::day05; use aoc2018::day05;
use aoc2018::Result;
fn main() -> Result<()> { fn main() -> Result<()> {
let days: &[fn() -> Result<()>] = &[day01::run, day02::run, day03::run, day04::run, day05::run]; let days: &[fn() -> Result<()>] = &[day01::run, day02::run, day03::run, day04::run, day05::run];

View file

@ -7,3 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
aoc = { path = "../aoc" }

View file

@ -1,4 +1,4 @@
use super::Result; use aoc::Result;
const INPUT: &str = include_str!("../input/day01.txt"); const INPUT: &str = include_str!("../input/day01.txt");