From 64410f0042d309ef3d2023b162d8ec02ca6205a9 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sun, 1 Dec 2019 22:22:12 +0100 Subject: [PATCH] use aoc crate for common stuff --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 1 + aoc/Cargo.toml | 9 +++++++++ aoc/src/lib.rs | 6 ++++++ aoc2015/Cargo.toml | 2 ++ aoc2015/src/day01.rs | 4 ++-- aoc2015/src/lib.rs | 7 ------- aoc2015/src/main.rs | 4 ++-- aoc2018/Cargo.toml | 2 ++ aoc2018/src/day01.rs | 2 +- aoc2018/src/day02.rs | 2 +- aoc2018/src/day03.rs | 4 ++-- aoc2018/src/day04.rs | 4 ++-- aoc2018/src/day05.rs | 2 +- aoc2018/src/lib.rs | 7 ------- aoc2018/src/main.rs | 4 ++-- aoc2019/Cargo.toml | 2 ++ aoc2019/src/day01.rs | 2 +- 18 files changed, 49 insertions(+), 28 deletions(-) create mode 100644 aoc/Cargo.toml create mode 100644 aoc/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3a8d771..58e58a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,14 +1,27 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aoc" +version = "0.1.0" + [[package]] name = "aoc2015" version = "0.1.0" +dependencies = [ + "aoc 0.1.0", +] [[package]] name = "aoc2018" version = "0.1.0" +dependencies = [ + "aoc 0.1.0", +] [[package]] name = "aoc2019" version = "0.1.0" +dependencies = [ + "aoc 0.1.0", +] diff --git a/Cargo.toml b/Cargo.toml index fd918d1..b105162 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "aoc", "aoc2015", "aoc2018", "aoc2019", diff --git a/aoc/Cargo.toml b/aoc/Cargo.toml new file mode 100644 index 0000000..7a169c1 --- /dev/null +++ b/aoc/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc" +version = "0.1.0" +authors = ["Antoine Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/aoc/src/lib.rs b/aoc/src/lib.rs new file mode 100644 index 0000000..16b7871 --- /dev/null +++ b/aoc/src/lib.rs @@ -0,0 +1,6 @@ +pub type Result = std::result::Result>; + +#[macro_export] +macro_rules! err { + ($($string:expr),+) => (Box::::from(format!($($string),+))) +} diff --git a/aoc2015/Cargo.toml b/aoc2015/Cargo.toml index 12a9c19..6749987 100644 --- a/aoc2015/Cargo.toml +++ b/aoc2015/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +aoc = { path = "../aoc" } diff --git a/aoc2015/src/day01.rs b/aoc2015/src/day01.rs index a9ed0ea..64dc249 100644 --- a/aoc2015/src/day01.rs +++ b/aoc2015/src/day01.rs @@ -1,5 +1,5 @@ -use super::err; -use super::Result; +use aoc::err; +use aoc::Result; const INPUT: &str = include_str!("../input/day01.txt"); diff --git a/aoc2015/src/lib.rs b/aoc2015/src/lib.rs index dc48b07..12b8f18 100644 --- a/aoc2015/src/lib.rs +++ b/aoc2015/src/lib.rs @@ -1,8 +1 @@ pub mod day01; - -pub type Result = std::result::Result>; - -#[macro_export] -macro_rules! err { - ($($string:expr),+) => (Box::::from(format!($($string),+))) -} diff --git a/aoc2015/src/main.rs b/aoc2015/src/main.rs index 3f01406..bcf06f4 100644 --- a/aoc2015/src/main.rs +++ b/aoc2015/src/main.rs @@ -1,8 +1,8 @@ use std::env; -use aoc2015::day01; +use aoc::Result; -use aoc2015::Result; +use aoc2015::day01; fn main() -> Result<()> { let days: &[fn() -> Result<()>] = &[day01::run]; diff --git a/aoc2018/Cargo.toml b/aoc2018/Cargo.toml index 5ebb51f..5a89598 100644 --- a/aoc2018/Cargo.toml +++ b/aoc2018/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +aoc = { path = "../aoc" } diff --git a/aoc2018/src/day01.rs b/aoc2018/src/day01.rs index 8695bff..e0b1d3d 100644 --- a/aoc2018/src/day01.rs +++ b/aoc2018/src/day01.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use super::Result; +use aoc::Result; const INPUT: &str = include_str!("../input/day01.txt"); diff --git a/aoc2018/src/day02.rs b/aoc2018/src/day02.rs index d4dfc3b..9c39af6 100644 --- a/aoc2018/src/day02.rs +++ b/aoc2018/src/day02.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use super::Result; +use aoc::Result; const INPUT: &str = include_str!("../input/day02.txt"); diff --git a/aoc2018/src/day03.rs b/aoc2018/src/day03.rs index 471b03d..9235b68 100644 --- a/aoc2018/src/day03.rs +++ b/aoc2018/src/day03.rs @@ -3,8 +3,8 @@ use std::collections::HashSet; use std::error::Error; use std::str::FromStr; -use super::err; -use super::Result; +use aoc::err; +use aoc::Result; const INPUT: &str = include_str!("../input/day03.txt"); diff --git a/aoc2018/src/day04.rs b/aoc2018/src/day04.rs index 0249f6d..51733de 100644 --- a/aoc2018/src/day04.rs +++ b/aoc2018/src/day04.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use std::error::Error; use std::str::FromStr; -use super::err; -use super::Result; +use aoc::err; +use aoc::Result; const INPUT: &str = include_str!("../input/day04.txt"); diff --git a/aoc2018/src/day05.rs b/aoc2018/src/day05.rs index b9c5f22..890bf1e 100644 --- a/aoc2018/src/day05.rs +++ b/aoc2018/src/day05.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use super::Result; +use aoc::Result; const INPUT: &str = include_str!("../input/day05.txt"); diff --git a/aoc2018/src/lib.rs b/aoc2018/src/lib.rs index e6a1200..f290640 100644 --- a/aoc2018/src/lib.rs +++ b/aoc2018/src/lib.rs @@ -3,10 +3,3 @@ pub mod day02; pub mod day03; pub mod day04; pub mod day05; - -pub type Result = std::result::Result>; - -#[macro_export] -macro_rules! err { - ($($string:expr),+) => (Box::::from(format!($($string),+))) -} diff --git a/aoc2018/src/main.rs b/aoc2018/src/main.rs index 5a23d0b..d2bd344 100644 --- a/aoc2018/src/main.rs +++ b/aoc2018/src/main.rs @@ -1,13 +1,13 @@ use std::env; +use aoc::Result; + use aoc2018::day01; use aoc2018::day02; use aoc2018::day03; use aoc2018::day04; use aoc2018::day05; -use aoc2018::Result; - fn main() -> Result<()> { let days: &[fn() -> Result<()>] = &[day01::run, day02::run, day03::run, day04::run, day05::run]; diff --git a/aoc2019/Cargo.toml b/aoc2019/Cargo.toml index 488af98..158ae3a 100644 --- a/aoc2019/Cargo.toml +++ b/aoc2019/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +aoc = { path = "../aoc" } diff --git a/aoc2019/src/day01.rs b/aoc2019/src/day01.rs index f196c11..4a7a10c 100644 --- a/aoc2019/src/day01.rs +++ b/aoc2019/src/day01.rs @@ -1,4 +1,4 @@ -use super::Result; +use aoc::Result; const INPUT: &str = include_str!("../input/day01.txt");