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

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

@ -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)",

@ -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"

@ -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()?;

@ -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