[2018][rust][07] make a main! macro
change qntyzysysorzwxmokpunmpltztxwunwt
commit 5cb055b64261038f6b13e6ab2db2f621d3474439
author Alpha Chen <alpha.chen@gmail.com>
date
parent luxonrpz
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 <alpha.chen@gmail.com>"]
 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<Error>> {
-    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<String, Box<Error>> {
     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<std::error::Error>> {
+            use std::io::{self, Read};
+
+            let mut input = String::new();
+            io::stdin().read_to_string(&mut input)?;
+
+            let output = solve(&input)?;
+            println!("{}", output);
+
+            Ok(())
+        }
+    }
+}