gstreamer/datetime: Add TryFrom impls for converting between glib::DateTime and gst::DateTime

This commit is contained in:
Sebastian Dröge 2020-03-22 12:31:10 +02:00
parent 7dd0404927
commit 962da8a63d

View file

@ -7,6 +7,7 @@
// except according to those terms.
use std::cmp;
use std::convert;
use std::fmt;
use DateTime;
@ -230,6 +231,38 @@ 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<DateTime, glib::BoolError> {
DateTime::new_from_g_date_time(v)
}
}
impl convert::TryFrom<glib::DateTime> for DateTime {
type Error = glib::BoolError;
fn try_from(v: glib::DateTime) -> Result<DateTime, glib::BoolError> {
DateTime::new_from_g_date_time(&v)
}
}
impl<'a> convert::TryFrom<&'a DateTime> for glib::DateTime {
type Error = glib::BoolError;
fn try_from(v: &'a DateTime) -> Result<glib::DateTime, glib::BoolError> {
v.to_g_date_time()
}
}
impl convert::TryFrom<DateTime> for glib::DateTime {
type Error = glib::BoolError;
fn try_from(v: DateTime) -> Result<glib::DateTime, glib::BoolError> {
v.to_g_date_time()
}
}
#[cfg(test)]
mod tests {
use super::*;