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,17 +141,15 @@ 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" ))
)) } else {
} else { Ok(fmt)
Ok(fmt)
}
} }
} }
} }

View file

@ -336,18 +336,15 @@ 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_string(s);
let fmt = Self::from_glib(ffi::gst_video_format_from_string(s.to_glib_none().0)); if fmt == Self::Unknown {
Err(glib::glib_bool_error!(
if fmt == Self::Unknown { "Failed to parse video format from string"
Err(glib::glib_bool_error!( ))
"Failed to parse video format from string" } else {
)) Ok(fmt)
} else {
Ok(fmt)
}
} }
} }
} }

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,
)))
}
} }
} }