]> aoc.elinar.fr Git - aoc_2023/commitdiff
Commit initial avec une maquette de jour
authoralex <null>
Fri, 1 Dec 2023 10:22:14 +0000 (11:22 +0100)
committeralex <null>
Sat, 2 Dec 2023 05:14:27 +0000 (06:14 +0100)
Cargo.toml [new file with mode: 0644]
src/day00.rs [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..2e8d130
--- /dev/null
@@ -0,0 +1,8 @@
+[package]
+name = "aoc_2023"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/day00.rs b/src/day00.rs
new file mode 100644 (file)
index 0000000..36171eb
--- /dev/null
@@ -0,0 +1,40 @@
+use std::error::Error;
+
+pub fn run() -> Result<(), Box<dyn Error>> {
+    let input = "blabl";
+    run_part1(&input)?;
+    run_part2(&input)?;
+    Ok(())
+}
+
+fn run_part1(input: &str) -> Result<String, Box<dyn Error>> {
+    println!("Running day00 (template) - part 1");
+    println!("{input}");
+    Ok(input.to_string())
+}
+
+fn run_part2(input: &str) -> Result<String, Box<dyn Error>> {
+    println!("Running day00 (template) - part 2");
+    Ok(input.to_string())
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn day00_part1() {
+        let input = "\
+blabla";
+        let res = run_part1(&input);
+        assert_eq!("blabla", res.unwrap());
+    }
+
+    #[test]
+    fn day00_part2() {
+        let input = "\
+blabla";
+        let res = run_part2(&input);
+        assert_eq!("blabla", res.unwrap());
+    }
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..c0378be
--- /dev/null
@@ -0,0 +1,27 @@
+use std::env;
+use std::process;
+use std::error::Error;
+
+pub mod day00;
+
+fn main() {
+    let args: Vec<String> = env::args().collect();
+    if args.len() != 2 {
+        println!("Missing argument");
+        process::exit(1);
+    }
+
+    if let Err(e) = run(args[1].clone()) {
+        println!("Error: {e}");
+        process::exit(1);
+    }
+}
+
+fn run(day: String) -> Result<(), Box<dyn Error>> {
+    if day == "day00" {
+        day00::run()?;
+    } else {
+        return Err(format!("unknown day \"{day}\"").into());
+    }
+    Ok(())
+}