Skip to content

Commit

Permalink
add the from trait challenge solution
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphonseMehounme committed Dec 7, 2024
1 parent 16f2870 commit 614bfca
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Rust/rustifinity/challenges/the-from-trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pub struct Minutes(pub i32);
pub struct Hours(pub i32);
pub struct Days(pub i32);

impl From<Minutes> 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<Hours> for Days {
fn from(hours: Hours) -> Days {
Days(hours.0 / 24)
}
}

// TODO: implement from minutes to days
impl From<Minutes> for Days {
fn from(minutes: Minutes) -> Days {
Days(minutes.0 / (24 * 60))
}
}

// TODO: implement from days to hours
impl From<Days> for Hours {
fn from(days: Days) -> Hours {
Hours(days.0 * 24)
}
}

0 comments on commit 614bfca

Please sign in to comment.