gstreamer: new_from_g_date_time only returns NULL if arg is NULL

This commit is contained in:
Marijn Suijten 2020-12-08 19:59:02 +01:00
parent 1d726d6a1e
commit bc5b44ddad
2 changed files with 10 additions and 10 deletions

View file

@ -1747,8 +1747,12 @@ status = "generate"
[[object.function]] [[object.function]]
name = "new_from_g_date_time" 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] [object.function.return]
nullable_return_is_error = "Can't create DateTime from glib::DateTime" nullable = false
[[object.function]] [[object.function]]
name = "to_g_date_time" name = "to_g_date_time"

View file

@ -308,7 +308,7 @@ impl DateTime {
d.to_utc() d.to_utc()
.ok_or_else(|| glib::glib_bool_error!("Can't convert datetime 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 { } else {
// It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly // It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly
// this would require using `glib::TimeZone::new_offset` which is feature-gated // 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 { impl<'a> From<&'a glib::DateTime> for DateTime {
type Error = glib::BoolError; fn from(v: &'a glib::DateTime) -> DateTime {
fn try_from(v: &'a glib::DateTime) -> Result<DateTime, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
DateTime::from_g_date_time(v) DateTime::from_g_date_time(v)
} }
} }
impl convert::TryFrom<glib::DateTime> for DateTime { impl From<glib::DateTime> for DateTime {
type Error = glib::BoolError; fn from(v: glib::DateTime) -> DateTime {
fn try_from(v: glib::DateTime) -> Result<DateTime, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
DateTime::from_g_date_time(&v) DateTime::from_g_date_time(&v)
} }