Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why impl TryInto<NaiveDateTime> for DateTime instead of impl TryFrom<DateTime> for NaiveDateTime? #136

Closed
sorairolake opened this issue May 19, 2024 · 1 comment

Comments

@sorairolake
Copy link

sorairolake commented May 19, 2024

zip2/src/types.rs

Lines 110 to 122 in 4b295d3

#[cfg(feature = "chrono")]
impl TryInto<NaiveDateTime> for DateTime {
type Error = DateTimeRangeError;
fn try_into(self) -> Result<NaiveDateTime, Self::Error> {
let date = NaiveDate::from_ymd_opt(self.year.into(), self.month.into(), self.day.into())
.ok_or(DateTimeRangeError)?;
let time =
NaiveTime::from_hms_opt(self.hour.into(), self.minute.into(), self.second.into())
.ok_or(DateTimeRangeError)?;
Ok(NaiveDateTime::new(date, time))
}
}

Why does this implement TryInto<NaiveDateTime> for DateTime instead of TryFrom<DateTime> for NaiveDateTime?

Pr0methean added a commit that referenced this issue May 19, 2024
@Pr0methean
Copy link
Member

I was unfamiliar with the convention that favors TryFrom as the explicitly-implemented trait. Fixed in 3afe549.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants