diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 964f042cb..a97e91d28 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -1424,10 +1424,34 @@ status = "generate" # Don't auto-implement traits name = "" + [[object.function]] + name = "new" + [object.function.return] + nullable = true + nullable_return_is_error = "Can't create DateTime" + + [[object.function]] + name = "new_y" + [object.function.return] + nullable = true + nullable_return_is_error = "Can't create DateTime" + + [[object.function]] + name = "new_ym" + [object.function.return] + nullable = true + nullable_return_is_error = "Can't create DateTime" + + [[object.function]] + name = "new_ymd" + [object.function.return] + nullable = true + nullable_return_is_error = "Can't create DateTime" + [[object.function]] name = "new_from_g_date_time" [object.function.return] - nullable = false + nullable_return_is_error = "Can't create DateTime from glib::DateTime" [[object.function]] name = "to_g_date_time" diff --git a/gstreamer/src/auto/date_time.rs b/gstreamer/src/auto/date_time.rs index f35904e31..2dd351b87 100644 --- a/gstreamer/src/auto/date_time.rs +++ b/gstreamer/src/auto/date_time.rs @@ -27,21 +27,23 @@ impl DateTime { hour: i32, minute: i32, seconds: f64, - ) -> DateTime { + ) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_sys::gst_date_time_new( + Option::<_>::from_glib_full(gst_sys::gst_date_time_new( tzoffset, year, month, day, hour, minute, seconds, )) + .ok_or_else(|| glib_bool_error!("Can't create DateTime")) } } - pub fn new_from_g_date_time(dt: &glib::DateTime) -> DateTime { + pub fn new_from_g_date_time(dt: &glib::DateTime) -> Result { assert_initialized_main_thread!(); unsafe { - from_glib_full(gst_sys::gst_date_time_new_from_g_date_time( + Option::<_>::from_glib_full(gst_sys::gst_date_time_new_from_g_date_time( dt.to_glib_full(), )) + .ok_or_else(|| glib_bool_error!("Can't create DateTime from glib::DateTime")) } } @@ -91,19 +93,28 @@ impl DateTime { unsafe { from_glib_full(gst_sys::gst_date_time_new_now_utc()) } } - pub fn new_y(year: i32) -> DateTime { + pub fn new_y(year: i32) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_full(gst_sys::gst_date_time_new_y(year)) } + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_date_time_new_y(year)) + .ok_or_else(|| glib_bool_error!("Can't create DateTime")) + } } - pub fn new_ym(year: i32, month: i32) -> DateTime { + pub fn new_ym(year: i32, month: i32) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_full(gst_sys::gst_date_time_new_ym(year, month)) } + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_date_time_new_ym(year, month)) + .ok_or_else(|| glib_bool_error!("Can't create DateTime")) + } } - pub fn new_ymd(year: i32, month: i32, day: i32) -> DateTime { + pub fn new_ymd(year: i32, month: i32, day: i32) -> Result { assert_initialized_main_thread!(); - unsafe { from_glib_full(gst_sys::gst_date_time_new_ymd(year, month, day)) } + unsafe { + Option::<_>::from_glib_full(gst_sys::gst_date_time_new_ymd(year, month, day)) + .ok_or_else(|| glib_bool_error!("Can't create DateTime")) + } } pub fn get_day(&self) -> i32 { diff --git a/gstreamer/src/date_time.rs b/gstreamer/src/date_time.rs index 0e66d339c..5d502de11 100644 --- a/gstreamer/src/date_time.rs +++ b/gstreamer/src/date_time.rs @@ -26,11 +26,11 @@ impl DateTime { // however, the resulting instance can't be translated to `glib::DateTime` if self.has_second() { self.to_g_date_time() - .expect("DateTime::to_utc: to_g_date_time") - .to_utc() - .as_ref() - .ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) - .map(DateTime::new_from_g_date_time) + .and_then(|d| { + d.to_utc() + .ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) + }) + .and_then(|d| DateTime::new_from_g_date_time(&d)) } else { // It would be cheaper to build a `glib::DateTime` direcly, unfortunetaly // this would require using `glib::TimeZone::new_offset` which is feature-gated @@ -45,18 +45,19 @@ impl DateTime { self.get_minute(), 0f64, ) - .to_g_date_time() - .expect("DateTime::to_utc: to_g_date_time") - .to_utc() - .ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) - .map(|g_date_time_utc| { + .and_then(|d| d.to_g_date_time()) + .and_then(|d| { + d.to_utc() + .ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) + }) + .and_then(|d| { DateTime::new( 0f32, // UTC TZ offset - g_date_time_utc.get_year(), - g_date_time_utc.get_month(), - g_date_time_utc.get_day_of_month(), - g_date_time_utc.get_hour(), - g_date_time_utc.get_minute(), + d.get_year(), + d.get_month(), + d.get_day_of_month(), + d.get_hour(), + d.get_minute(), -1f64, // No second ) }) @@ -240,6 +241,7 @@ mod tests { // Hour offset let utc_date_time = DateTime::new(2f32, 2019, 8, 20, 20, 9, 42.123_456f64) + .unwrap() .to_utc() .unwrap(); assert_eq!(utc_date_time.get_year(), 2019); @@ -252,6 +254,7 @@ mod tests { // Year, month, day and hour offset let utc_date_time = DateTime::new(2f32, 2019, 1, 1, 0, 0, 42.123_456f64) + .unwrap() .to_utc() .unwrap(); assert_eq!(utc_date_time.get_year(), 2018); @@ -263,7 +266,7 @@ mod tests { assert_eq!(utc_date_time.get_microsecond(), 123_456); // Date without an hour (which implies no TZ) - let utc_date_time = DateTime::new_ymd(2019, 1, 1).to_utc().unwrap(); + let utc_date_time = DateTime::new_ymd(2019, 1, 1).unwrap().to_utc().unwrap(); assert_eq!(utc_date_time.get_year(), 2019); assert_eq!(utc_date_time.get_month(), 1); assert_eq!(utc_date_time.get_day(), 1); @@ -272,6 +275,7 @@ mod tests { // Date without seconds let utc_date_time = DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64) + .unwrap() .to_utc() .unwrap(); assert_eq!(utc_date_time.get_year(), 2018); @@ -288,96 +292,102 @@ mod tests { // Different years assert!( - DateTime::new(2f32, 2020, 8, 20, 19, 43, 42.123_456f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2020, 8, 20, 19, 43, 42.123_456f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // Different months (order intentionally reversed) assert!( - DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) - < DateTime::new(2f32, 2019, 9, 19, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() + < DateTime::new(2f32, 2019, 9, 19, 19, 43, 42.123_456f64).unwrap() ); // Different days assert!( - DateTime::new(2f32, 2019, 8, 21, 19, 43, 42.123_456f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2019, 8, 21, 19, 43, 42.123_456f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // Different hours assert!( - DateTime::new(2f32, 2019, 8, 20, 19, 44, 42.123_456f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2019, 8, 20, 19, 44, 42.123_456f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // Different minutes assert!( - DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // Different seconds assert!( - DateTime::new(2f32, 2019, 8, 20, 19, 43, 43.123_456f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2019, 8, 20, 19, 43, 43.123_456f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // Different micro-seconds assert!( - DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_457f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_457f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // Different TZ offsets assert!( - DateTime::new(1f32, 2019, 8, 20, 19, 43, 42.123_456f64) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64) + DateTime::new(1f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 42.123_456f64).unwrap() ); // TZ offset leading to year, month, day, hour offset assert!( - DateTime::new(2f32, 2019, 1, 1, 0, 0, 0f64) - < DateTime::new(1f32, 2018, 12, 31, 23, 59, 0f64) + DateTime::new(2f32, 2019, 1, 1, 0, 0, 0f64).unwrap() + < DateTime::new(1f32, 2018, 12, 31, 23, 59, 0f64).unwrap() ); // Partially defined `DateTime` - assert!(DateTime::new_ymd(2020, 8, 20) > DateTime::new_ymd(2019, 8, 20)); - assert!(DateTime::new_ymd(2019, 9, 20) > DateTime::new_ymd(2019, 8, 20)); - assert!(DateTime::new_ymd(2019, 8, 21) > DateTime::new_ymd(2019, 8, 20)); + assert!(DateTime::new_ymd(2020, 8, 20).unwrap() > DateTime::new_ymd(2019, 8, 20).unwrap()); + assert!(DateTime::new_ymd(2019, 9, 20).unwrap() > DateTime::new_ymd(2019, 8, 20).unwrap()); + assert!(DateTime::new_ymd(2019, 8, 21).unwrap() > DateTime::new_ymd(2019, 8, 20).unwrap()); - assert!(DateTime::new_ym(2020, 8) > DateTime::new_ym(2019, 8)); - assert!(DateTime::new_ym(2019, 9) > DateTime::new_ym(2019, 8)); - assert!(DateTime::new_ym(2019, 9) > DateTime::new_ymd(2019, 8, 20)); + assert!(DateTime::new_ym(2020, 8).unwrap() > DateTime::new_ym(2019, 8).unwrap()); + assert!(DateTime::new_ym(2019, 9).unwrap() > DateTime::new_ym(2019, 8).unwrap()); + assert!(DateTime::new_ym(2019, 9).unwrap() > DateTime::new_ymd(2019, 8, 20).unwrap()); - assert!(DateTime::new_y(2020) > DateTime::new_y(2019)); - assert!(DateTime::new_ym(2020, 1) > DateTime::new_y(2019)); + assert!(DateTime::new_y(2020).unwrap() > DateTime::new_y(2019).unwrap()); + assert!(DateTime::new_ym(2020, 1).unwrap() > DateTime::new_y(2019).unwrap()); assert!( - DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64) - < DateTime::new_ymd(2020, 8, 20) + DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64).unwrap() + < DateTime::new_ymd(2020, 8, 20).unwrap() ); assert!( - DateTime::new_ymd(2020, 8, 20) - > DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64) + DateTime::new_ymd(2020, 8, 20).unwrap() + > DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64).unwrap() ); // Comparison occurs on the same TZ when the `DateTime` doesn't have time (note 2) - assert!(DateTime::new_ymd(2020, 1, 1) > DateTime::new(-2f32, 2019, 12, 31, 23, 59, 0f64)); + assert!( + DateTime::new_ymd(2020, 1, 1).unwrap() + > DateTime::new(-2f32, 2019, 12, 31, 23, 59, 0f64).unwrap() + ); // In the following cases, the partially defined `DateTime` is a range WRT // the fully defined `DateTime` and this range includes the fully defined `DateTime`, // but we can't tell if it's before or after and they are not equal (note 1) assert!(DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64) - .partial_cmp(&DateTime::new_ymd(2019, 8, 20)) + .unwrap() + .partial_cmp(&DateTime::new_ymd(2019, 8, 20).unwrap()) .is_none()); assert!(DateTime::new_ymd(2019, 8, 20) - .partial_cmp(&DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64)) + .unwrap() + .partial_cmp(&DateTime::new(2f32, 2019, 8, 20, 19, 43, 44.123_456f64).unwrap()) .is_none()); assert!(DateTime::new_ym(2019, 1) - .partial_cmp(&DateTime::new_y(2019)) + .unwrap() + .partial_cmp(&DateTime::new_y(2019).unwrap()) .is_none()); } @@ -386,41 +396,41 @@ mod tests { ::init().unwrap(); assert_eq!( - DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64), - DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64) + DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap(), + DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap() ); assert_eq!( - DateTime::new(2f32, 2018, 5, 28, 16, 6, 0f64), - DateTime::new(2f32, 2018, 5, 28, 16, 6, 0f64) + DateTime::new(2f32, 2018, 5, 28, 16, 6, 0f64).unwrap(), + DateTime::new(2f32, 2018, 5, 28, 16, 6, 0f64).unwrap() ); assert_eq!( - DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64), - DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64) + DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap(), + DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap() ); assert_eq!( - DateTime::new_ymd(2018, 5, 28), - DateTime::new_ymd(2018, 5, 28) + DateTime::new_ymd(2018, 5, 28).unwrap(), + DateTime::new_ymd(2018, 5, 28).unwrap() ); // In the following cases, the partially defined `DateTime` is a range WRT // the fully defined `DateTime` and this range includes the fully defined `DateTime`, // but they are not equal (note 1) assert_ne!( - DateTime::new_ymd(2018, 5, 28), - DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64) + DateTime::new_ymd(2018, 5, 28).unwrap(), + DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap() ); assert_ne!( - DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64), - DateTime::new_ym(2018, 5) + DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap(), + DateTime::new_ym(2018, 5).unwrap() ); assert_ne!( - DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64), - DateTime::new_y(2018) + DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap(), + DateTime::new_y(2018).unwrap() ); } } diff --git a/gstreamer/src/date_time_serde.rs b/gstreamer/src/date_time_serde.rs index 690f01a8c..2f1ea2416 100644 --- a/gstreamer/src/date_time_serde.rs +++ b/gstreamer/src/date_time_serde.rs @@ -135,8 +135,10 @@ impl<'de> Deserialize<'de> for Date { } #[allow(clippy::many_single_char_names)] -impl From for DateTime { - fn from(dt_variant: DateTimeVariants) -> Self { +impl TryFrom for DateTime { + type Error = glib::BoolError; + + fn try_from(dt_variant: DateTimeVariants) -> Result { match dt_variant { DateTimeVariants::Y(y) => DateTime::new_y(y), DateTimeVariants::YM(y, m) => DateTime::new_ym(y, m), @@ -153,7 +155,8 @@ impl From for DateTime { impl<'de> Deserialize<'de> for DateTime { fn deserialize>(deserializer: D) -> Result { - DateTimeVariants::deserialize(deserializer).map(|dt_variant| dt_variant.into()) + DateTimeVariants::deserialize(deserializer) + .and_then(|dt_variant| dt_variant.try_into().map_err(D::Error::custom)) } } @@ -171,7 +174,7 @@ mod tests { let mut pretty_config = ron::ser::PrettyConfig::default(); pretty_config.new_line = "".to_string(); - let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64); + let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap(); let res = ron::ser::to_string_pretty(&datetime, pretty_config.clone()); assert_eq!( Ok("YMDhmsTz(2018, 5, 28, 16, 6, 42.123456, 2)".to_owned()), @@ -184,19 +187,19 @@ mod tests { res ); - let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64); + let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap(); let res = ron::ser::to_string_pretty(&datetime, pretty_config.clone()); assert_eq!(Ok("YMDhmTz(2018, 5, 28, 16, 6, 2)".to_owned()), res,); - let datetime = DateTime::new_ymd(2018, 5, 28); + let datetime = DateTime::new_ymd(2018, 5, 28).unwrap(); let res = ron::ser::to_string_pretty(&datetime, pretty_config.clone()); assert_eq!(Ok("YMD(2018, 5, 28)".to_owned()), res); - let datetime = DateTime::new_ym(2018, 5); + let datetime = DateTime::new_ym(2018, 5).unwrap(); let res = ron::ser::to_string_pretty(&datetime, pretty_config.clone()); assert_eq!(Ok("YM(2018, 5)".to_owned()), res); - let datetime = DateTime::new_y(2018); + let datetime = DateTime::new_y(2018).unwrap(); let res = ron::ser::to_string_pretty(&datetime, pretty_config); assert_eq!(Ok("Y(2018)".to_owned()), res); } @@ -209,58 +212,61 @@ mod tests { let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap(); assert_eq!( datetime_de, - DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64) + DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap() ); let datetime_json = r#"{"YMDhmsTz":[2018,5,28,16,6,42.123456,2.0]}"#; let datetime_de: DateTime = serde_json::from_str(datetime_json).unwrap(); assert_eq!( datetime_de, - DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64) + DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap() ); let datetime_ron = "YMDhmTz(2018, 5, 28, 16, 6, 2)"; let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap(); - assert_eq!(datetime_de, DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64)); + assert_eq!( + datetime_de, + DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap() + ); let datetime_ron = "YMD(2018, 5, 28)"; let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap(); - assert_eq!(datetime_de, DateTime::new_ymd(2018, 5, 28)); + assert_eq!(datetime_de, DateTime::new_ymd(2018, 5, 28).unwrap()); let datetime_ron = "YM(2018, 5)"; let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap(); - assert_eq!(datetime_de, DateTime::new_ym(2018, 5)); + assert_eq!(datetime_de, DateTime::new_ym(2018, 5).unwrap()); let datetime_ron = "Y(2018)"; let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap(); - assert_eq!(datetime_de, DateTime::new_y(2018)); + assert_eq!(datetime_de, DateTime::new_y(2018).unwrap()); } #[test] fn test_serde_roundtrip() { ::init().unwrap(); - let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64); + let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap(); let datetime_ser = ron::ser::to_string(&datetime).unwrap(); let datetime_de: DateTime = ron::de::from_str(datetime_ser.as_str()).unwrap(); assert_eq!(datetime_de, datetime); - let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64); + let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, -1f64).unwrap(); let datetime_ser = ron::ser::to_string(&datetime).unwrap(); let datetime_de: DateTime = ron::de::from_str(datetime_ser.as_str()).unwrap(); assert_eq!(datetime_de, datetime); - let datetime = DateTime::new_ymd(2018, 5, 28); + let datetime = DateTime::new_ymd(2018, 5, 28).unwrap(); let datetime_ser = ron::ser::to_string(&datetime).unwrap(); let datetime_de: DateTime = ron::de::from_str(datetime_ser.as_str()).unwrap(); assert_eq!(datetime_de, datetime); - let datetime = DateTime::new_ym(2018, 5); + let datetime = DateTime::new_ym(2018, 5).unwrap(); let datetime_ser = ron::ser::to_string(&datetime).unwrap(); let datetime_de: DateTime = ron::de::from_str(datetime_ser.as_str()).unwrap(); assert_eq!(datetime_de, datetime); - let datetime = DateTime::new_y(2018); + let datetime = DateTime::new_y(2018).unwrap(); let datetime_ser = ron::ser::to_string(&datetime).unwrap(); let datetime_de: DateTime = ron::de::from_str(datetime_ser.as_str()).unwrap(); assert_eq!(datetime_de, datetime); diff --git a/gstreamer/src/structure_serde.rs b/gstreamer/src/structure_serde.rs index 56ac30322..61966e6a0 100644 --- a/gstreamer/src/structure_serde.rs +++ b/gstreamer/src/structure_serde.rs @@ -186,7 +186,7 @@ mod tests { .field("date", &Date::new_dmy(19, DateMonth::August, 2019)) .field( "date_time", - &DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64), + &DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap(), ) .field("array", &Array::new(&[&1, &2])) .build(); @@ -244,7 +244,7 @@ mod tests { ("date", &Date::new_dmy(19, DateMonth::August, 2019)), ( "date_time", - &DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64) + &DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap() ), ("fraction", &Fraction::new(1, 2)), ("array", &Array::new(&[&1, &2])), @@ -266,7 +266,7 @@ mod tests { .field("date", &Date::new_dmy(19, DateMonth::August, 2019)) .field( "date_time", - &DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64), + &DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap(), ) .field("array", &Array::new(&[&1, &2])) .build(); diff --git a/gstreamer/src/tags_serde.rs b/gstreamer/src/tags_serde.rs index eb61514dd..46ed1903c 100644 --- a/gstreamer/src/tags_serde.rs +++ b/gstreamer/src/tags_serde.rs @@ -347,7 +347,10 @@ mod tests { &glib::Date::new_dmy(28, glib::DateMonth::May, 2018), TagMergeMode::Append, ); - tags.add::(&::DateTime::new_ymd(2018, 5, 28), TagMergeMode::Append); + tags.add::( + &::DateTime::new_ymd(2018, 5, 28).unwrap(), + TagMergeMode::Append, + ); let sample = { let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]); @@ -497,7 +500,7 @@ mod tests { ); assert_eq!( tags.get_index::(0).unwrap().get().unwrap(), - ::DateTime::new_ymd(2018, 5, 28) + ::DateTime::new_ymd(2018, 5, 28).unwrap() ); let sample = tags.get_index::(0).unwrap().get().unwrap(); let buffer = sample.get_buffer().unwrap(); @@ -538,7 +541,7 @@ mod tests { ); assert_eq!( tags.get_index::(0).unwrap().get().unwrap(), - ::DateTime::new_ymd(2018, 5, 28) + ::DateTime::new_ymd(2018, 5, 28).unwrap() ); let sample = tags.get_index::(0).unwrap().get().unwrap(); let buffer = sample.get_buffer().unwrap(); @@ -566,7 +569,10 @@ mod tests { &glib::Date::new_dmy(28, glib::DateMonth::May, 2018), TagMergeMode::Append, ); - tags.add::(&::DateTime::new_ymd(2018, 5, 28), TagMergeMode::Append); + tags.add::( + &::DateTime::new_ymd(2018, 5, 28).unwrap(), + TagMergeMode::Append, + ); let sample = { let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]); @@ -612,7 +618,7 @@ mod tests { ); assert_eq!( tags.get_index::(0).unwrap().get().unwrap(), - ::DateTime::new_ymd(2018, 5, 28) + ::DateTime::new_ymd(2018, 5, 28).unwrap() ); let sample = tags.get_index::(0).unwrap().get().unwrap(); let buffer = sample.get_buffer().unwrap(); diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index 3958c0912..8186b90e5 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -433,7 +433,9 @@ mod tests { let value_str_none = str_none.to_value(); let send_value_str_none = value_str_none.try_into_send_value::().unwrap(); - let value_date_time = DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).to_value(); + let value_date_time = DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64) + .unwrap() + .to_value(); let send_value_date_time = value_date_time.try_into_send_value::().unwrap(); let date_time_none: Option = None; @@ -648,7 +650,7 @@ mod tests { assert!(slice[2].get::().expect("slice[2]").is_none()); assert_eq!( - DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64), + DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).unwrap(), slice[3].get::().expect("slice[3]").unwrap() ); @@ -723,7 +725,9 @@ mod tests { let str_none: Option<&str> = None; let value_str_none = str_none.to_value(); let send_value_str_none = value_str_none.try_into_send_value::().unwrap(); - let value_date_time = DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64).to_value(); + let value_date_time = DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64) + .unwrap() + .to_value(); let send_value_date_time = value_date_time.try_into_send_value::().unwrap(); let date_time_none: Option = None; let value_date_time_none = date_time_none.to_value();