From 33208c1c35807bf7036d20ebe8f525aaa688df38 Mon Sep 17 00:00:00 2001
From: Pierre Paquin
Date: Sat, 6 Jul 2024 15:56:45 +0200
Subject: [PATCH] feat: day01 for rust
---
exercise/rust/day01/Cargo.lock | 367 +++++++++++++++++++
exercise/rust/day01/Cargo.toml | 11 +
exercise/rust/day01/src/food.rs | 15 +
exercise/rust/day01/src/lib.rs | 1 +
exercise/rust/day01/tests/mod.rs | 1 +
exercise/rust/day01/tests/unit_tests/food.rs | 66 ++++
exercise/rust/day01/tests/unit_tests/mod.rs | 1 +
solution/rust/day01/Cargo.lock | 367 +++++++++++++++++++
solution/rust/day01/Cargo.toml | 11 +
solution/rust/day01/src/food.rs | 28 ++
solution/rust/day01/src/lib.rs | 1 +
solution/rust/day01/tests/mod.rs | 1 +
solution/rust/day01/tests/unit_tests/food.rs | 66 ++++
solution/rust/day01/tests/unit_tests/mod.rs | 1 +
14 files changed, 937 insertions(+)
create mode 100644 exercise/rust/day01/Cargo.lock
create mode 100644 exercise/rust/day01/Cargo.toml
create mode 100644 exercise/rust/day01/src/food.rs
create mode 100644 exercise/rust/day01/src/lib.rs
create mode 100644 exercise/rust/day01/tests/mod.rs
create mode 100644 exercise/rust/day01/tests/unit_tests/food.rs
create mode 100644 exercise/rust/day01/tests/unit_tests/mod.rs
create mode 100644 solution/rust/day01/Cargo.lock
create mode 100644 solution/rust/day01/Cargo.toml
create mode 100644 solution/rust/day01/src/food.rs
create mode 100644 solution/rust/day01/src/lib.rs
create mode 100644 solution/rust/day01/tests/mod.rs
create mode 100644 solution/rust/day01/tests/unit_tests/food.rs
create mode 100644 solution/rust/day01/tests/unit_tests/mod.rs
diff --git a/exercise/rust/day01/Cargo.lock b/exercise/rust/day01/Cargo.lock
new file mode 100644
index 000000000..d11b9dd85
--- /dev/null
+++ b/exercise/rust/day01/Cargo.lock
@@ -0,0 +1,367 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "android-tzdata"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
+
+[[package]]
+name = "android_system_properties"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
+
+[[package]]
+name = "bumpalo"
+version = "3.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
+
+[[package]]
+name = "cc"
+version = "1.0.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "chrono"
+version = "0.4.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
+dependencies = [
+ "android-tzdata",
+ "iana-time-zone",
+ "js-sys",
+ "num-traits",
+ "wasm-bindgen",
+ "windows-targets",
+]
+
+[[package]]
+name = "core-foundation-sys"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
+
+[[package]]
+name = "day01"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "once_cell",
+ "uuid",
+]
+
+[[package]]
+name = "getrandom"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
+name = "iana-time-zone"
+version = "0.1.60"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
+dependencies = [
+ "android_system_properties",
+ "core-foundation-sys",
+ "iana-time-zone-haiku",
+ "js-sys",
+ "wasm-bindgen",
+ "windows-core",
+]
+
+[[package]]
+name = "iana-time-zone-haiku"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
+dependencies = [
+ "cc",
+]
+
+[[package]]
+name = "js-sys"
+version = "0.3.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
+dependencies = [
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.155"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
+
+[[package]]
+name = "log"
+version = "0.4.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
+
+[[package]]
+name = "ppv-lite86"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.86"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rand"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
+dependencies = [
+ "libc",
+ "rand_chacha",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
+dependencies = [
+ "getrandom",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.68"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
+[[package]]
+name = "uuid"
+version = "1.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439"
+dependencies = [
+ "getrandom",
+ "rand",
+ "uuid-macro-internal",
+]
+
+[[package]]
+name = "uuid-macro-internal"
+version = "1.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a3ff64d5cde1e2cb5268bdb497235b6bd255ba8244f910dbc3574e59593de68c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
+dependencies = [
+ "cfg-if",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
+dependencies = [
+ "bumpalo",
+ "log",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
+
+[[package]]
+name = "windows-core"
+version = "0.52.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
diff --git a/exercise/rust/day01/Cargo.toml b/exercise/rust/day01/Cargo.toml
new file mode 100644
index 000000000..59a101bdd
--- /dev/null
+++ b/exercise/rust/day01/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "day01"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+chrono = "0.4.38"
+uuid = { version = "1.9.1", features = ["v4", "fast-rng", "macro-diagnostics"] }
+once_cell = "1.19.0"
\ No newline at end of file
diff --git a/exercise/rust/day01/src/food.rs b/exercise/rust/day01/src/food.rs
new file mode 100644
index 000000000..6b3eb8a45
--- /dev/null
+++ b/exercise/rust/day01/src/food.rs
@@ -0,0 +1,15 @@
+use chrono::{DateTime, Utc};
+
+pub struct Food {
+ pub expiration_date: DateTime,
+ pub approved_for_consumption: bool,
+ pub inspector_id: Option,
+}
+
+impl Food {
+ pub fn is_edible(&self, now: &DateTime) -> bool {
+ self.expiration_date > *now &&
+ self.approved_for_consumption &&
+ self.inspector_id.is_some()
+ }
+}
\ No newline at end of file
diff --git a/exercise/rust/day01/src/lib.rs b/exercise/rust/day01/src/lib.rs
new file mode 100644
index 000000000..0eda3b6b1
--- /dev/null
+++ b/exercise/rust/day01/src/lib.rs
@@ -0,0 +1 @@
+pub mod food;
\ No newline at end of file
diff --git a/exercise/rust/day01/tests/mod.rs b/exercise/rust/day01/tests/mod.rs
new file mode 100644
index 000000000..f35915624
--- /dev/null
+++ b/exercise/rust/day01/tests/mod.rs
@@ -0,0 +1 @@
+pub mod unit_tests;
\ No newline at end of file
diff --git a/exercise/rust/day01/tests/unit_tests/food.rs b/exercise/rust/day01/tests/unit_tests/food.rs
new file mode 100644
index 000000000..9154b0c67
--- /dev/null
+++ b/exercise/rust/day01/tests/unit_tests/food.rs
@@ -0,0 +1,66 @@
+use std::ops::{Sub, Add, Deref};
+use chrono::{DateTime, Duration, Utc};
+use once_cell::sync::Lazy;
+use uuid::Uuid;
+
+use day01::food::Food;
+
+
+#[test]
+fn not_edible_if_not_fresh() {
+ let arguments = vec![
+ (true, Some(&INSPECTOR), &NOT_FRESH_DATE),
+ (false, Some(&INSPECTOR), &FRESH_DATE),
+ (true, None, &FRESH_DATE),
+ (false, None, &NOT_FRESH_DATE),
+ (false, None, &FRESH_DATE),
+ ];
+
+ let res = arguments
+ .into_iter()
+ .map(|(approved, inspertor_id, date_expiration)| {
+ Food {
+ expiration_date: *(date_expiration.deref()),
+ approved_for_consumption: approved,
+ inspector_id: inspertor_id.map(|x| *(x.deref())),
+ }
+ })
+ .map(|food| food.is_edible(NOW.deref()))
+ .any(|x| !x);
+
+ assert!(res)
+}
+
+#[test]
+fn edible_food() {
+
+ let food = Food {
+ expiration_date: *(EXPIRATION_DATE.deref()),
+ approved_for_consumption: true,
+ inspector_id: Some(*INSPECTOR.deref()),
+ };
+
+ let is_edible = food.is_edible(FRESH_DATE.deref());
+
+ assert!(is_edible)
+}
+
+
+static NOW: Lazy> = Lazy::new(|| {
+ Utc::now()
+});
+
+static INSPECTOR: Lazy = Lazy::new(|| {
+ Uuid::new_v4()
+});
+
+static EXPIRATION_DATE: Lazy> = Lazy::new(|| {
+ *NOW.deref()
+});
+static NOT_FRESH_DATE: Lazy> = Lazy::new(|| {
+ EXPIRATION_DATE.add(Duration::days(7))
+});
+
+static FRESH_DATE: Lazy> = Lazy::new(|| {
+ EXPIRATION_DATE.sub(Duration::days(7))
+});
\ No newline at end of file
diff --git a/exercise/rust/day01/tests/unit_tests/mod.rs b/exercise/rust/day01/tests/unit_tests/mod.rs
new file mode 100644
index 000000000..0eda3b6b1
--- /dev/null
+++ b/exercise/rust/day01/tests/unit_tests/mod.rs
@@ -0,0 +1 @@
+pub mod food;
\ No newline at end of file
diff --git a/solution/rust/day01/Cargo.lock b/solution/rust/day01/Cargo.lock
new file mode 100644
index 000000000..d11b9dd85
--- /dev/null
+++ b/solution/rust/day01/Cargo.lock
@@ -0,0 +1,367 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "android-tzdata"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
+
+[[package]]
+name = "android_system_properties"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
+
+[[package]]
+name = "bumpalo"
+version = "3.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
+
+[[package]]
+name = "cc"
+version = "1.0.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "chrono"
+version = "0.4.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
+dependencies = [
+ "android-tzdata",
+ "iana-time-zone",
+ "js-sys",
+ "num-traits",
+ "wasm-bindgen",
+ "windows-targets",
+]
+
+[[package]]
+name = "core-foundation-sys"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
+
+[[package]]
+name = "day01"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "once_cell",
+ "uuid",
+]
+
+[[package]]
+name = "getrandom"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
+name = "iana-time-zone"
+version = "0.1.60"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
+dependencies = [
+ "android_system_properties",
+ "core-foundation-sys",
+ "iana-time-zone-haiku",
+ "js-sys",
+ "wasm-bindgen",
+ "windows-core",
+]
+
+[[package]]
+name = "iana-time-zone-haiku"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
+dependencies = [
+ "cc",
+]
+
+[[package]]
+name = "js-sys"
+version = "0.3.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
+dependencies = [
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.155"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
+
+[[package]]
+name = "log"
+version = "0.4.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
+
+[[package]]
+name = "ppv-lite86"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.86"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rand"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
+dependencies = [
+ "libc",
+ "rand_chacha",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
+dependencies = [
+ "getrandom",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.68"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
+[[package]]
+name = "uuid"
+version = "1.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439"
+dependencies = [
+ "getrandom",
+ "rand",
+ "uuid-macro-internal",
+]
+
+[[package]]
+name = "uuid-macro-internal"
+version = "1.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a3ff64d5cde1e2cb5268bdb497235b6bd255ba8244f910dbc3574e59593de68c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
+dependencies = [
+ "cfg-if",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
+dependencies = [
+ "bumpalo",
+ "log",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
+
+[[package]]
+name = "windows-core"
+version = "0.52.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
diff --git a/solution/rust/day01/Cargo.toml b/solution/rust/day01/Cargo.toml
new file mode 100644
index 000000000..59a101bdd
--- /dev/null
+++ b/solution/rust/day01/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "day01"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+chrono = "0.4.38"
+uuid = { version = "1.9.1", features = ["v4", "fast-rng", "macro-diagnostics"] }
+once_cell = "1.19.0"
\ No newline at end of file
diff --git a/solution/rust/day01/src/food.rs b/solution/rust/day01/src/food.rs
new file mode 100644
index 000000000..66435aa41
--- /dev/null
+++ b/solution/rust/day01/src/food.rs
@@ -0,0 +1,28 @@
+use chrono::{DateTime, Utc};
+
+pub struct Food {
+ pub expiration_date: DateTime,
+ pub approved_for_consumption: bool,
+ pub inspector_id: Option,
+}
+
+impl Food {
+ pub fn is_edible(&self, now: &DateTime) -> bool {
+ self.is_fresh(now) &&
+ self.can_be_consumed() &&
+ self.has_been_inspected()
+ }
+
+ fn is_fresh(&self, now: &DateTime) -> bool {
+ self.expiration_date > *now
+ }
+
+ fn has_been_inspected(&self) -> bool {
+ self.inspector_id.is_some()
+ }
+
+ fn can_be_consumed(&self) -> bool {
+ self.approved_for_consumption
+ }
+
+}
\ No newline at end of file
diff --git a/solution/rust/day01/src/lib.rs b/solution/rust/day01/src/lib.rs
new file mode 100644
index 000000000..0eda3b6b1
--- /dev/null
+++ b/solution/rust/day01/src/lib.rs
@@ -0,0 +1 @@
+pub mod food;
\ No newline at end of file
diff --git a/solution/rust/day01/tests/mod.rs b/solution/rust/day01/tests/mod.rs
new file mode 100644
index 000000000..f35915624
--- /dev/null
+++ b/solution/rust/day01/tests/mod.rs
@@ -0,0 +1 @@
+pub mod unit_tests;
\ No newline at end of file
diff --git a/solution/rust/day01/tests/unit_tests/food.rs b/solution/rust/day01/tests/unit_tests/food.rs
new file mode 100644
index 000000000..9154b0c67
--- /dev/null
+++ b/solution/rust/day01/tests/unit_tests/food.rs
@@ -0,0 +1,66 @@
+use std::ops::{Sub, Add, Deref};
+use chrono::{DateTime, Duration, Utc};
+use once_cell::sync::Lazy;
+use uuid::Uuid;
+
+use day01::food::Food;
+
+
+#[test]
+fn not_edible_if_not_fresh() {
+ let arguments = vec![
+ (true, Some(&INSPECTOR), &NOT_FRESH_DATE),
+ (false, Some(&INSPECTOR), &FRESH_DATE),
+ (true, None, &FRESH_DATE),
+ (false, None, &NOT_FRESH_DATE),
+ (false, None, &FRESH_DATE),
+ ];
+
+ let res = arguments
+ .into_iter()
+ .map(|(approved, inspertor_id, date_expiration)| {
+ Food {
+ expiration_date: *(date_expiration.deref()),
+ approved_for_consumption: approved,
+ inspector_id: inspertor_id.map(|x| *(x.deref())),
+ }
+ })
+ .map(|food| food.is_edible(NOW.deref()))
+ .any(|x| !x);
+
+ assert!(res)
+}
+
+#[test]
+fn edible_food() {
+
+ let food = Food {
+ expiration_date: *(EXPIRATION_DATE.deref()),
+ approved_for_consumption: true,
+ inspector_id: Some(*INSPECTOR.deref()),
+ };
+
+ let is_edible = food.is_edible(FRESH_DATE.deref());
+
+ assert!(is_edible)
+}
+
+
+static NOW: Lazy> = Lazy::new(|| {
+ Utc::now()
+});
+
+static INSPECTOR: Lazy = Lazy::new(|| {
+ Uuid::new_v4()
+});
+
+static EXPIRATION_DATE: Lazy> = Lazy::new(|| {
+ *NOW.deref()
+});
+static NOT_FRESH_DATE: Lazy> = Lazy::new(|| {
+ EXPIRATION_DATE.add(Duration::days(7))
+});
+
+static FRESH_DATE: Lazy> = Lazy::new(|| {
+ EXPIRATION_DATE.sub(Duration::days(7))
+});
\ No newline at end of file
diff --git a/solution/rust/day01/tests/unit_tests/mod.rs b/solution/rust/day01/tests/unit_tests/mod.rs
new file mode 100644
index 000000000..0eda3b6b1
--- /dev/null
+++ b/solution/rust/day01/tests/unit_tests/mod.rs
@@ -0,0 +1 @@
+pub mod food;
\ No newline at end of file