-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the from trait challenge solution
- Loading branch information
1 parent
16f2870
commit 614bfca
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |