From bc5b44ddadb33f27838e8ff697d90c0bde5a0706 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 8 Dec 2020 19:59:02 +0100 Subject: [PATCH] gstreamer: new_from_g_date_time only returns NULL if arg is NULL --- gstreamer/Gir.toml | 6 +++++- gstreamer/src/date_time.rs | 14 +++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index ba4606dd7..cb7bf4d13 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -1747,8 +1747,12 @@ status = "generate" [[object.function]] name = "new_from_g_date_time" + # Function only ever returns NULL if the argument is NULL + [[object.function.parameter]] + name = "dt" + nullable = false [object.function.return] - nullable_return_is_error = "Can't create DateTime from glib::DateTime" + nullable = false [[object.function]] name = "to_g_date_time" diff --git a/gstreamer/src/date_time.rs b/gstreamer/src/date_time.rs index 67242297e..cf488f8c2 100644 --- a/gstreamer/src/date_time.rs +++ b/gstreamer/src/date_time.rs @@ -308,7 +308,7 @@ impl DateTime { d.to_utc() .ok_or_else(|| glib::glib_bool_error!("Can't convert datetime to UTC")) }) - .and_then(|d| DateTime::from_g_date_time(&d)) + .map(|d| d.into()) } else { // It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly // this would require using `glib::TimeZone::new_offset` which is feature-gated @@ -508,19 +508,15 @@ impl fmt::Display for DateTime { } } -impl<'a> convert::TryFrom<&'a glib::DateTime> for DateTime { - type Error = glib::BoolError; - - fn try_from(v: &'a glib::DateTime) -> Result { +impl<'a> From<&'a glib::DateTime> for DateTime { + fn from(v: &'a glib::DateTime) -> DateTime { skip_assert_initialized!(); DateTime::from_g_date_time(v) } } -impl convert::TryFrom for DateTime { - type Error = glib::BoolError; - - fn try_from(v: glib::DateTime) -> Result { +impl From for DateTime { + fn from(v: glib::DateTime) -> DateTime { skip_assert_initialized!(); DateTime::from_g_date_time(&v) }