impl FromStr: Forward implementation to autogenerated from_string()

This commit is contained in:
Marijn Suijten 2020-11-15 16:49:07 +01:00
parent a7348023a0
commit 82b4726bb7
3 changed files with 27 additions and 32 deletions

View file

@ -141,10 +141,9 @@ impl str::FromStr for crate::AudioFormat {
type Err = glib::BoolError; type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_initialized_main_thread!(); skip_assert_initialized!();
unsafe { let fmt = Self::from_string(s);
let fmt = Self::from_glib(ffi::gst_audio_format_from_string(s.to_glib_none().0));
if fmt == Self::Unknown { if fmt == Self::Unknown {
Err(glib::glib_bool_error!( Err(glib::glib_bool_error!(
"Failed to parse audio format from string" "Failed to parse audio format from string"
@ -154,7 +153,6 @@ impl str::FromStr for crate::AudioFormat {
} }
} }
} }
}
impl PartialOrd for crate::AudioFormat { impl PartialOrd for crate::AudioFormat {
fn partial_cmp(&self, other: &crate::AudioFormat) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &crate::AudioFormat) -> Option<std::cmp::Ordering> {

View file

@ -336,11 +336,9 @@ impl str::FromStr for crate::VideoFormat {
type Err = glib::BoolError; type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_initialized_main_thread!(); skip_assert_initialized!();
unsafe {
let fmt = Self::from_glib(ffi::gst_video_format_from_string(s.to_glib_none().0));
let fmt = Self::from_string(s);
if fmt == Self::Unknown { if fmt == Self::Unknown {
Err(glib::glib_bool_error!( Err(glib::glib_bool_error!(
"Failed to parse video format from string" "Failed to parse video format from string"
@ -350,7 +348,6 @@ impl str::FromStr for crate::VideoFormat {
} }
} }
} }
}
impl PartialOrd for crate::VideoFormat { impl PartialOrd for crate::VideoFormat {
fn partial_cmp(&self, other: &crate::VideoFormat) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &crate::VideoFormat) -> Option<std::cmp::Ordering> {

View file

@ -956,12 +956,15 @@ impl str::FromStr for crate::VideoFieldOrder {
type Err = glib::error::BoolError; type Err = glib::error::BoolError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_initialized_main_thread!(); skip_assert_initialized!();
unsafe { let fmt = Self::from_string(s);
Ok(from_glib(ffi::gst_video_field_order_from_string( if fmt == Self::Unknown {
s.to_glib_none().0, Err(glib::glib_bool_error!(
))) "Failed to parse video field order from string"
))
} else {
Ok(fmt)
} }
} }
} }
@ -970,13 +973,10 @@ impl str::FromStr for crate::VideoInterlaceMode {
type Err = glib::error::BoolError; type Err = glib::error::BoolError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_initialized_main_thread!(); skip_assert_initialized!();
unsafe { let fmt = Self::from_string(s);
Ok(from_glib(ffi::gst_video_interlace_mode_from_string( Ok(fmt)
s.to_glib_none().0,
)))
}
} }
} }