From 4576ad656c3ac460675b3a5fdb4c01de8e808639 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 8 Dec 2018 21:58:19 -0800 Subject: [PATCH] [2018][rust][07] make a main! macro --- 2018/rust/Cargo.lock | 2 +- 2018/rust/Cargo.toml | 2 +- 2018/rust/src/bin/day_07.rs | 11 ++--------- 2018/rust/src/lib.rs | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 2018/rust/src/lib.rs diff --git a/2018/rust/Cargo.lock b/2018/rust/Cargo.lock index 0bd80e1..6fcda3f 100644 --- a/2018/rust/Cargo.lock +++ b/2018/rust/Cargo.lock @@ -1,5 +1,5 @@ [[package]] -name = "advent_of_code_2018" +name = "advent_of_code" version = "0.1.0" dependencies = [ "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/2018/rust/Cargo.toml b/2018/rust/Cargo.toml index 5281b4b..ee90d0d 100644 --- a/2018/rust/Cargo.toml +++ b/2018/rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "advent_of_code_2018" +name = "advent_of_code" version = "0.1.0" authors = ["Alpha Chen "] edition = "2018" diff --git a/2018/rust/src/bin/day_07.rs b/2018/rust/src/bin/day_07.rs index a42071e..7676920 100644 --- a/2018/rust/src/bin/day_07.rs +++ b/2018/rust/src/bin/day_07.rs @@ -3,20 +3,13 @@ use std::cmp::{Ord, Ordering}; use std::collections::{HashMap, HashSet}; use std::error::Error; -use std::io::{self, Read}; use std::str::FromStr; use regex::Regex; -fn main() -> Result<(), Box> { - let mut input = String::new(); - io::stdin().read_to_string(&mut input)?; +use advent_of_code::main; - let output = solve(&input)?; - println!("{}", output); - - Ok(()) -} +main!(); fn solve(input: &str) -> Result> { let assembly: Assembly = input.parse()?; diff --git a/2018/rust/src/lib.rs b/2018/rust/src/lib.rs new file mode 100644 index 0000000..6cbc9aa --- /dev/null +++ b/2018/rust/src/lib.rs @@ -0,0 +1,16 @@ +#[macro_export] +macro_rules! main { + () => { + fn main() -> Result<(), Box> { + use std::io::{self, Read}; + + let mut input = String::new(); + io::stdin().read_to_string(&mut input)?; + + let output = solve(&input)?; + println!("{}", output); + + Ok(()) + } + } +}