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 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);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 { 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(); hours.into() }}// 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 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/1440 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 as i32) }}// 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/1440 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 as i32) }}// 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 / 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 let hours: i32 = minutes.0 / 60; Hours(hours) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { let days: i32 = hours.0 / 24; Days(days) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { let days: i32 = minutes.0 / 60 / 24; Days(days) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { let hours: i32 = days.0 * 24; Hours(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(value: Hours) -> Self { Self(value.0 / 24) }}// TODO: implement from hours to days// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(value: Minutes) -> Self { Self(value.0 / 60 / 24) }}// TODO: implement from days to hoursimpl 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 { 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) -> 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) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}
const MINUTES_IN_HOUR: i32 = 60;const HOURS_IN_DAY: i32 = 24;const MINUTES_IN_DAY: i32 = MINUTES_IN_HOUR * HOURS_IN_DAY;pub struct Minutes(pub i32);pub struct Hours(pub i32);pub struct Days(pub i32);impl From<Minutes> for Hours { fn from(minutes: Minutes) -> Self { Hours(minutes.0 / MINUTES_IN_HOUR) }}impl From<Hours> for Days { fn from(hours: Hours) -> Self { Days(hours.0 / HOURS_IN_DAY) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Days(minutes.0 / MINUTES_IN_DAY) }}impl From<Days> for Hours { fn from(days: Days) -> Self { Hours(days.0 * HOURS_IN_DAY) }}// 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) }}// 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 { let result = minutes.0 / 60; Hours(result) }}impl From<Hours> for Days { fn from(hours: Hours) -> Self { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Days(minutes.0 / ( 60 * 24)) }}impl From<Days> for Hours { fn from(days: Days) -> Self { 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 { let result = minutes.0 / 60; Hours(result) }}impl From<Hours> for Days { fn from(hours: Hours) -> Self { Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Days(minutes.0 / 60 / 24) }}impl From<Days> for Hours { fn from(days: Days) -> Self { 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 / (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) }}// 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 { // 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 Into::<Hours>::into(minutes).into() }}// 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 her 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) }}// 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 / (60 * 24)) }}// 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 { 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 { // 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 / (24 * 60)) }}// 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/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);}
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 let hour = minutes.0/60; Hours(hour) }}// 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 let x = (minutes.0 as f64) / (60 as f64); Hours(x as i32) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { let x = (hours.0 as f64) / (24 as f64); Days(x as i32) }} // TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { let x = (minutes.0 as f64) / (24 as f64 * 60 as f64); Days(x as i32) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { let x = days.0 * 24; Hours(x as i32) }}// 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 / 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) // 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) }}// 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(value: Hours) -> Self { Self(value.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(value: Minutes) -> Self { Hours::from(value).into() }}// TODO: implement from days to hoursimpl 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 { 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) }}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 { let val: i32 = minutes.0; Hours(val / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { let val: i32 = hours.0; Days(val / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { let val: i32 = minutes.0; Days(val / 60 / 24) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { let val: i32 = days.0; Hours(val * 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 { 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/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) -> Self { Self(minutes.0 / 60) }}impl From<Hours> for Days { fn from(hours: Hours) -> Self { Self(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Self(minutes.0 / (60 * 24)) }}impl From<Days> for Hours { fn from(days: Days) -> Self { Self(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(hour: Hours) -> Days { Days(hour.0/24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(min:Minutes) -> Days { Days(min.0 /1440) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(day: Days) -> Hours { Hours(day.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 { // Implement the minute to hour conversion here Days(minutes.0 / (24 * 60)) }}// 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) // 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) }}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 { // Implement the minute to hour conversion here let hours = minutes.0 / 60; Hours(hours) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the minute to hour conversion here let days = hours.0 / 24; Days(days) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to hour conversion here let days = minutes.0 / 1440; // 60 minutes * 24 hours Days(days) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Hours { // Implement the minute to hour conversion here let hours = days.0 * 24; Hours(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) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the minute to hour conversion here Days(hours.0 / 24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to hour conversion here Days(minutes.0 / 1440) }}impl 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) }}impl From<Hours> for Days { fn from(hours: Hours) -> Days { // Implement the minute to hour conversion here Days(hours.0/24) }}impl From<Minutes> for Days { fn from(minutes: Minutes) -> Days { // Implement the minute to hour conversion here Days(minutes.0/1440) }}impl From<Days> for Hours { fn from(days: Days) -> Hours { // Implement the minute to hour conversion here 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(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 u32);pub struct Hours(pub u32);pub struct Days(pub u32);impl From<Minutes> for Hours { fn from(minutes: Minutes) -> Self { Self(minutes.0 / 60) }}// TODO: implement from hours to daysimpl From<Hours> for Days { fn from(hours: Hours) -> Self { Self(hours.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(minutes: Minutes) -> Self { Self(minutes.0 / (60 * 24)) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(days: Days) -> Self { Self(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 / 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) }}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 ) }}// 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(); 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 ) }}// 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 / (24 * 60)) }}// 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(h: Hours) -> Days { Days(h.0 / 24) }}// TODO: implement from minutes to daysimpl From<Minutes> for Days { fn from(m: Minutes) -> Days { Days(m.0 / 24/60) }}// TODO: implement from days to hoursimpl From<Days> for Hours { fn from(d: Days) -> Hours { Hours(d.0 * 24) }}// Example usagepub fn main() { let minutes = Minutes(60); let hours: Hours = minutes.into(); assert_eq!(hours.0, 1);}