summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorcos <cos>2021-12-04 11:29:30 +0100
committercos <cos>2021-12-07 14:06:16 +0100
commitf4979b0c8e32678710cbda681c36d5faa94444c1 (patch)
treec1b755742074915ec6167d12e87b15ec6e9f3943 /bin
parentb785c4dc3b7287eea8478e38669a47febb87e3fa (diff)
downloadadventofcode-f4979b0c8e32678710cbda681c36d5faa94444c1.zip
Add some boiler plate generation to init_rust
Diffstat (limited to 'bin')
-rwxr-xr-xbin/init_rust.sh59
1 files changed, 58 insertions, 1 deletions
diff --git a/bin/init_rust.sh b/bin/init_rust.sh
index 5388a69..681ecf8 100755
--- a/bin/init_rust.sh
+++ b/bin/init_rust.sh
@@ -20,7 +20,64 @@ cat > 'Cargo.toml' << END_OF_TOML
name = "day${DAY}"
version = "0.1.0"
authors = ["${GIT_USER} <${GIT_EMAIL}>"]
-edition = "2018"
+edition = "2021"
[dependencies]
+aoc = { path = "../../../common/rust/aoc" }
+anyhow = "1.0"
END_OF_TOML
+
+cat > 'src/main.rs' << END_OF_SRC
+use {
+ anyhow::{
+ anyhow,
+ Context,
+ Result,
+ },
+ std::{
+ env::args,
+ fs::File,
+ io::{
+ BufRead,
+ BufReader,
+ },
+ path::Path,
+ },
+};
+
+fn read_input<T: AsRef<Path>>(filename: T) -> Result<Vec<usize>> {
+ let reader = BufReader::new(File::open(filename)?);
+
+ reader.lines().map(
+ |v| {
+ let s = v?;
+ let n = s.parse()?;
+ Ok(n)
+ }
+ ).collect()
+}
+
+fn part1<'a, I: IntoIterator<Item = &'a usize>>(input: I) -> Result<usize> {
+ Ok(0)
+}
+
+fn part2<'a, I: IntoIterator<Item = &'a usize>>(input: I) -> Result<usize> {
+ Ok(0)
+}
+
+fn main() -> Result<()> {
+ let ( do_part_1, do_part_2 ) = aoc::do_parts();
+
+ let filename = args().nth(1).ok_or(anyhow!("Missing input filename"))?;
+ let input = read_input(filename).context("Could not read input")?;
+ if do_part_1 {
+ let solution = part1(&input).context("No solution for part 1")?;
+ println!("Part1, solution found to be: {}", solution);
+ }
+ if do_part_2 {
+ let solution = part2(&input).context("No solution for part 2")?;
+ println!("Part2, solution found to be: {}", solution);
+ }
+ Ok(())
+}
+END_OF_SRC