[2018][rust][07] make a main! macro

sorbet
Alpha Chen 6 years ago
parent 958353d539
commit 4576ad656c

@ -1,5 +1,5 @@
[[package]] [[package]]
name = "advent_of_code_2018" name = "advent_of_code"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",

@ -1,5 +1,5 @@
[package] [package]
name = "advent_of_code_2018" name = "advent_of_code"
version = "0.1.0" version = "0.1.0"
authors = ["Alpha Chen <alpha.chen@gmail.com>"] authors = ["Alpha Chen <alpha.chen@gmail.com>"]
edition = "2018" edition = "2018"

@ -3,20 +3,13 @@
use std::cmp::{Ord, Ordering}; use std::cmp::{Ord, Ordering};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::error::Error; use std::error::Error;
use std::io::{self, Read};
use std::str::FromStr; use std::str::FromStr;
use regex::Regex; use regex::Regex;
fn main() -> Result<(), Box<Error>> { use advent_of_code::main;
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
let output = solve(&input)?; main!();
println!("{}", output);
Ok(())
}
fn solve(input: &str) -> Result<String, Box<Error>> { fn solve(input: &str) -> Result<String, Box<Error>> {
let assembly: Assembly = input.parse()?; let assembly: Assembly = input.parse()?;

@ -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(())
}
}
}
Loading…
Cancel
Save