From 3d4d46f35ee3c255b60035bbd917f4fb96245e01 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Tue, 22 Feb 2022 06:20:01 +0100
Subject: [PATCH] Add Rust project for 2020 & update README

---
 2020/.gitignore   |  1 +
 2020/Cargo.lock   |  7 +++++++
 2020/Cargo.toml   |  4 ++++
 2020/utils/mod.rs | 14 ++++++++++++++
 README.md         | 12 +++++++++---
 build.gradle.kts  |  5 +++--
 6 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 2020/.gitignore
 create mode 100644 2020/Cargo.lock
 create mode 100644 2020/Cargo.toml
 create mode 100644 2020/utils/mod.rs

diff --git a/2020/.gitignore b/2020/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/2020/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/2020/Cargo.lock b/2020/Cargo.lock
new file mode 100644
index 0000000..aa3ebce
--- /dev/null
+++ b/2020/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "chylex-aoc-2020"
+version = "0.1.0"
diff --git a/2020/Cargo.toml b/2020/Cargo.toml
new file mode 100644
index 0000000..85927ac
--- /dev/null
+++ b/2020/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "chylex-aoc-2020"
+version = "0.1.0"
+edition = "2021"
diff --git a/2020/utils/mod.rs b/2020/utils/mod.rs
new file mode 100644
index 0000000..70bf0ed
--- /dev/null
+++ b/2020/utils/mod.rs
@@ -0,0 +1,14 @@
+use std::error::Error;
+use std::fs::File;
+use std::io;
+use std::io::{BufRead, BufReader};
+use std::str::FromStr;
+
+pub fn read_input_lines() -> Result<Vec<String>, io::Error> {
+	let file = File::open("input/1.txt")?;
+	return BufReader::new(file).lines().collect();
+}
+
+pub fn parse_input_lines<T : FromStr>() -> Result<Vec<T>, Box<dyn Error>> where <T as FromStr>::Err : Into<Box<dyn Error>> {
+	return read_input_lines()?.iter().map(|line| line.parse::<T>()).collect::<Result<Vec<T>, T::Err>>().map_err(Into::into);
+}
diff --git a/README.md b/README.md
index f8bd0f0..842d2d0 100644
--- a/README.md
+++ b/README.md
@@ -6,15 +6,21 @@ I have included Run Configurations for JetBrains IDEs, so if you use the appropr
 
 # Languages
 
-## Kotlin
+## \[2021\] Kotlin
 
 The repository contains a Gradle project (`build.gradle.kts`) that sets up every day as a module. You should be able to load the Gradle project into [IntelliJ IDEA](https://www.jetbrains.com/idea/).
 
 The source code is in `main.kt`. The run configuration executes the `main()` method in this file.
 
-## NASM x64 Assembly
+## \[2020\] Rust
 
-The repository contains a CMake project (`CMakeLists.txt`) in the respective year's folder, which sets up every day as a CMake subproject. You should be able to load the CMake project into [CLion](https://www.jetbrains.com/clion/), as long as you have a toolchain named `Visual Studio x64` set to use the `amd64` architecture.
+The repository contains a Cargo project (`2020/Cargo.toml`) that sets up every day as a binary target that can be launched with `cargo run --bin <day>`, for ex. `cargo run --bin 01`. You should be able to load the Cargo project into [CLion](https://www.jetbrains.com/clion/).
+
+The source code is in `main.rs`. The run configuration executes the `main()` function in this file.
+
+## \[2015\] NASM x64 Assembly
+
+The repository contains a CMake project (`2015/CMakeLists.txt`) in the respective year's folder, which sets up every day as a CMake subproject. You should be able to load the CMake project into [CLion](https://www.jetbrains.com/clion/), as long as you have a toolchain named `Visual Studio x64` set to use the `amd64` architecture.
 
 The source code is in `main.c`, which is either in the puzzle's own folder, or in `utils` if no adjustments are needed. By default, `main.c` reads the whole input file into a buffer, and passes it as a parameter to the `entryPoint` function defined in `main.asm` which implements the logic and output of each puzzle.
 
diff --git a/build.gradle.kts b/build.gradle.kts
index 67e7e02..b803edb 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -18,8 +18,9 @@ idea {
 	module.excludeDirs.addAll(listOf(
 		file(".gradle"),
 		file("build"),
-		file("cmake-build-debug"),
-		file("gradle")
+		file("gradle"),
+		file("2015"),
+		file("2020")
 	))
 }