The From trait is one of the most commonly used trait in the Rust programming language, it is used for converting a value from one type to another.
After you implement the From trait for a type, the Into trait is implemented for you automatically. This means that you can then use into() on the source type to convert this type to the target type, and of course, you can use From::from() to convert from the source type to the target type.
Here's an example on a use case for the From trait:
fn main() {
let f = Fahrenheit(32.0);
let c: Celsius = f.into();
println!("{}°F is {}°C", f.0, c.0);
}This code works because the Fahrenheit struct implements the From trait for the Celsius struct. This allows us to convert a Fahrenheit instance to a Celsius instance using the into() method. The explicit type annotation : Celsius tells the compiler to turn it "into" a Celsius instance.
Your task is to implement the From trait for the following struct types:
struct Minutes(u32);
struct Hours(u32);
struct Days(u32);You need to implement the From trait for the following conversions:
Minutes to HoursHours to DaysMinutes to DaysDays to Hourspub 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 let quotient = minutes.0/60; Hours(quotient) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) } }// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days((minutes.0/60)/24) } }// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) } }// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days((minutes.0 / 60) / 24) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(24 * days.0) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60i32)}}impl From<Hours> for Days{fn from(hours: Hours) -> Days { Days(hours.0 / 24i32)}}impl From<Minutes> for Days {fn from(minutes: Minutes)-> Days {Days(minutes.0 /60i32 / 24i32)}}impl From<Days> for Hours {fn from(days:Days)->Hours {Hours(days.0 * 24i32)}}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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) as i32) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the minute to hour conversion here Days((hours.0 / 24) as i32) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to hour conversion here Days((minutes.0 / 24 / 60) as i32) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { // Implement the minute to hour conversion here Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (60 * 24)) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (60 * 24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 *24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);impl From<Minutes> for Hours { fn from(Minutes(minutes): Minutes) -> Hours { // Implement the minute to hour conversion here Hours(minutes / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(Hours(hours): Hours) -> Days { Days(hours / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { let hours: Hours = minutes.into(); hours.into() }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from (Days(days): Days) -> Hours { Hours(days * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}/*You need to implement the From trait for the following conversions: Minutes to Hours Hours to Days Minutes to Days Days to Hours*/pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Hours { fn from(minutes: Minutes) -> Hours { Hours(minutes.0 / 60) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { let hours: Hours = minutes.into(); let days: Days = hours.into(); days }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0*24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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_i32) }}impl From<Hours> for Days{ fn from(hours : Hours) -> Days{ Days(hours.0 / 24_i32) }}impl From<Minutes> for Days{ fn from(minutes : Minutes) -> Days{ Days(minutes.0 / 1440_i32) }}impl From<Days> for Hours{ fn from(days : Days) -> Hours{ Hours(days.0 * 24_i32) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days{ fn from(hours: Hours) -> Days{ Days(hours.0 / 24) }}impl From<Minutes> for Days{ fn from(minutes: Minutes) -> Days{ Days(minutes.0 / 60 / 24) }}impl From<Days> for Hours{ fn from(days: Days) -> Hours{ Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0/1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 60 / 24) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 60 / 24) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}pub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (24 * 60)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (60 * 24)) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the minute to hour conversion here Days(hours.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to hour conversion here Days(minutes.0 / 1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { // Implement the minute to hour conversion here Hours(days.0*24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the hour to day conversion here Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to day conversion here Days(minutes.0 / (60 * 24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { // Implement the day to hour conversion here Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days::from(Hours::from(minutes)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0/(60*24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0*24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0/(60*24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0*24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 60 / 24) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (60 * 24)) }}// FIX 1: Implement From<Days> for Hours.// The generic argument is necessary to specify the input type Days.impl From<Days> for Hours { fn from(days: Days) -> Hours { // Access the inner value of the Days struct using .0 Hours(days.0 * 24) }}// FIX 2: Implement From<Minutes> for Hours (for the main example to work).impl From<Minutes> for Hours { fn from(minutes: Minutes) -> Hours { // Convert minutes to hours (60 minutes per hour) Hours(minutes.0 / 60) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) // Implement the minute to hour conversion here }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (24 * 60)) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) // Implement the minute to hour conversion here }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (24 * 60)) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days::from(Hours::from(minutes)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { let hours: Hours = minutes.into(); Days(hours.0 / 24) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);impl From<Minutes> for Hours { fn from(m: Minutes) -> Hours { // Implement the minute to hour conversion here Hours(m.0 / 60) }}impl From<Hours> for Days { fn from(h: Hours) -> Days { Days(h.0 / 24) }}impl From<Minutes> for Days { fn from(m: Minutes) -> Days { Days(m.0 / 1440) }}impl From<Days> for Hours { fn from (d: Days) -> Hours { Hours(d.0 * 24) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);impl From<Minutes> for Hours { fn from(value: Minutes) -> Self { Self(value.0 / 60) }}impl From<Hours> for Days { fn from(value: Hours) -> Self { Self(value.0 / 24) }}impl From<Minutes> for Days { fn from(value: Minutes) -> Self { Self(value.0 / 60 / 24) }}impl From<Days> for Hours { fn from(value: Days) -> Self { Self(value.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the hour to day conversion here Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to day conversion here Days(minutes.0 / 1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { // Implement the day to hour conversion here Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days{ fn from(hr: Hours) -> Days{ Days(hr.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days{ fn from(minutes: Minutes) -> Days{ Days(minutes.0 / 60 / 24) }}// TODO: implement from days to hoursimpl From<Days> for Hours{ fn from(days: Days) -> Hours{ Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days::from(Hours::from(minutes)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1_440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0/60) // Implement the minute to hour conversion here }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0/(60*24)) // Implement the minute to hour conversion here }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) // Implement the minute to hour conversion here }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days ( hours.0 / 24 ) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days ( minutes.0 / (24 * 60) ) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours ( days.0 * 24 ) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days((minutes.0 / 60) / 24) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 return Hours(minutes.0 / 60); }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { return Days(hours.0 / 24); }} // TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { return Days(minutes.0 / 60 / 24); }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { return Hours(days.0 * 24); }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (60 * 24)) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0/60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0/(60*24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0*24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Self { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Days(minutes.0 / 60 / 24 ) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Self { // Implement the minute to hour conversion here Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) // Implement the minute to hour conversion here }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) // Implement the minute to hour conversion here }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days((minutes.0 / 60) / 24) // Implement the minute to hour conversion here }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) // Implement the minute to hour conversion here }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Self { // Implement the minute to hour conversion here Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Days(minutes.0 / (60 * 24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Self { Hours(days.0 * 24) }}impl From<Minutes> for Hours { fn from(minutes: Minutes) -> Self { Hours(minutes.0 / 60) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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) }}impl From<Hours> for Days { fn from(value: Hours) -> Self { Days(value.0 / 24) }}impl From<Minutes> for Days { fn from(value: Minutes) -> Self { Days(value.0 / 60 / 24) }}impl From<Days> for Hours { fn from(value: Days) -> Self { Hours(value.0 * 24) }}// TODO: implement from hours to days// TODO: implement from minutes to days// TODO: implement from days to hours// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1440) // 1440 minutes in a day }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0 / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / 1440) // 1440 minutes in a day }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the minute to hour conversion here Days(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0 / (60 * 24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}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 { Hours(minutes.0/60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { Days(hours.0/24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { Days(minutes.0/1440) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { Hours(days.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}