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) + } +}