From 614bfcae19f5e40853b62367b8243b58e90e1729 Mon Sep 17 00:00:00 2001 From: AlphonseMehounme Date: Sat, 7 Dec 2024 18:52:56 +0100 Subject: [PATCH] add the from trait challenge solution --- Rust/rustifinity/challenges/the-from-trait.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Rust/rustifinity/challenges/the-from-trait.rs diff --git a/Rust/rustifinity/challenges/the-from-trait.rs b/Rust/rustifinity/challenges/the-from-trait.rs new file mode 100644 index 0000000..79a9703 --- /dev/null +++ b/Rust/rustifinity/challenges/the-from-trait.rs @@ -0,0 +1,31 @@ +pub struct Minutes(pub i32); +pub struct Hours(pub i32); +pub struct Days(pub i32); + +impl From for Hours { + fn from(minutes: Minutes) -> Hours { + // Implement the minute to hour conversion here + Hours(minutes.0 / 60) + } +} + +// TODO: implement from hours to days +impl From for Days { + fn from(hours: Hours) -> Days { + Days(hours.0 / 24) + } +} + +// TODO: implement from minutes to days +impl From for Days { + fn from(minutes: Minutes) -> Days { + Days(minutes.0 / (24 * 60)) + } +} + +// TODO: implement from days to hours +impl From for Hours { + fn from(days: Days) -> Hours { + Hours(days.0 * 24) + } +}