├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── src └── lib.rs └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | .idea -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "aoc-runner" 3 | version = "0.2.2" 4 | 5 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "aoc-runner" 3 | version = "0.2.2" 4 | authors = ["Grégory Obanos "] 5 | description = "A runner for the Advent of Code" 6 | license = "MIT/Apache-2.0" 7 | repository = "https://github.com/gobanos/aoc-runner" 8 | readme = "README.md" 9 | 10 | [dependencies] -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::fmt::Display; 3 | use std::sync::Arc; 4 | use std::borrow::Borrow; 5 | 6 | #[inline] 7 | pub fn identity(t: T) -> T { 8 | t 9 | } 10 | 11 | #[derive(Clone, Debug)] 12 | pub struct ArcStr(Arc); 13 | 14 | impl ArcStr { 15 | #[inline] 16 | pub fn from(f: &str) -> ArcStr { 17 | ArcStr(Arc::from(f.trim_end_matches('\n'))) 18 | } 19 | } 20 | 21 | impl Borrow for ArcStr { 22 | fn borrow(&self) -> &str { 23 | self.0.borrow() 24 | } 25 | } 26 | 27 | impl Borrow<[u8]> for ArcStr { 28 | fn borrow(&self) -> &[u8] { 29 | self.0.as_bytes() 30 | } 31 | } 32 | 33 | impl Borrow> for ArcStr { 34 | fn borrow(&self) -> &Arc { 35 | &self.0 36 | } 37 | } 38 | 39 | pub trait Runner { 40 | fn gen(input: ArcStr) -> Self 41 | where 42 | Self: Sized; 43 | 44 | fn run(&self) -> Box; 45 | 46 | fn bench(&self, black_box: fn(&dyn Display)); 47 | 48 | fn try_gen(input: ArcStr) -> Result> 49 | where 50 | Self: Sized, 51 | { 52 | Ok(Self::gen(input)) 53 | } 54 | 55 | fn try_run(&self) -> Result, Box> { 56 | Ok(self.run()) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Repository moved to [cargo-aoc/aoc-runner](https://github.com/gobanos/cargo-aoc/tree/v0.3/aoc-runner) 2 | 3 | # Advent of Code Runner 4 | 5 | This is a simple project that aims to be a runner for the [Advent of Code](https://adventofcode.com). 6 | 7 | Implement your solution. Let us do the rest. 8 | 9 | # Features 10 | * Input downloading 11 | * Running your solution 12 | * Benchmarking of your solution (WIP) 13 | 14 | # Getting started 15 | 16 | * Create a lib project `cargo new advent-of-code-2018 --lib` 17 | * Add deps to your Cargo.toml: 18 | ``` 19 | aoc-runner = "0.1.0" 20 | aoc-runner-derive = "0.1.0" 21 | ``` 22 | * Include libs in your lib.rs 23 | ``` 24 | extern crate aoc_runner; 25 | 26 | #[macro_use] 27 | extern crate aoc_runner_derive; 28 | ``` 29 | 30 | * Add `aoc_lib!{ year = 2018 }` at the end of your lib.rs 31 | * Start coding ! 32 | 33 | # Flags your solutions 34 | 35 | just add a `#[aoc(day1, part1)]` before your function ! 36 | ``` 37 | #[aoc(day1, part1)] 38 | fn part1(input: &str) -> i32 { 39 | ... 40 | } 41 | ``` 42 | Supported signatures : `&str` or `&[u8]` as input, any type implementing display as output. 43 | For custom input, see below. 44 | 45 | # Custom Generators 46 | 47 | You need to pre-process input in a separated function ? generators are for you ! 48 | ``` 49 | #[aoc_generator(day2)] 50 | fn input_generator(input: &str) -> Vec { 51 | ... 52 | } 53 | 54 | #[aoc(day2, part1)] 55 | fn part1(input: &[Gift]) -> u32 { 56 | ... 57 | } 58 | ``` 59 | 60 | # Run your code 61 | See [cargo-aoc](https://github.com/gobanos/cargo-aoc) 62 | --------------------------------------------------------------------------------