mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
video: Reuse Self::Err in from_str
This commit is contained in:
parent
2447664df6
commit
0763d2645d
10 changed files with 29 additions and 32 deletions
|
@ -138,14 +138,12 @@ impl crate::AudioFormat {
|
|||
impl str::FromStr for crate::AudioFormat {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
unsafe {
|
||||
let fmt = crate::AudioFormat::from_glib(ffi::gst_audio_format_from_string(
|
||||
s.to_glib_none().0,
|
||||
));
|
||||
if fmt == crate::AudioFormat::Unknown {
|
||||
let fmt = Self::from_glib(ffi::gst_audio_format_from_string(s.to_glib_none().0));
|
||||
if fmt == Self::Unknown {
|
||||
Err(glib::glib_bool_error!(
|
||||
"Failed to parse audio format from string"
|
||||
))
|
||||
|
|
|
@ -292,10 +292,10 @@ impl fmt::Display for AudioFormatInfo {
|
|||
impl str::FromStr for crate::AudioFormatInfo {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
skip_assert_initialized!();
|
||||
let format = s.parse()?;
|
||||
Ok(AudioFormatInfo::from_format(format))
|
||||
Ok(Self::from_format(format))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -339,15 +339,13 @@ impl crate::VideoFormat {
|
|||
impl str::FromStr for crate::VideoFormat {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
unsafe {
|
||||
let fmt = crate::VideoFormat::from_glib(ffi::gst_video_format_from_string(
|
||||
s.to_glib_none().0,
|
||||
));
|
||||
let fmt = Self::from_glib(ffi::gst_video_format_from_string(s.to_glib_none().0));
|
||||
|
||||
if fmt == crate::VideoFormat::Unknown {
|
||||
if fmt == Self::Unknown {
|
||||
Err(glib::glib_bool_error!(
|
||||
"Failed to parse video format from string"
|
||||
))
|
||||
|
|
|
@ -431,10 +431,10 @@ impl fmt::Display for VideoFormatInfo {
|
|||
impl str::FromStr for crate::VideoFormatInfo {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
skip_assert_initialized!();
|
||||
let format = s.parse()?;
|
||||
Ok(VideoFormatInfo::from_format(format))
|
||||
Ok(Self::from_format(format))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ impl Eq for VideoColorimetry {}
|
|||
impl str::FromStr for crate::VideoColorimetry {
|
||||
type Err = glib::error::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
unsafe {
|
||||
|
@ -149,7 +149,7 @@ impl str::FromStr for crate::VideoColorimetry {
|
|||
s.to_glib_none().0,
|
||||
));
|
||||
if valid {
|
||||
Ok(VideoColorimetry(colorimetry.assume_init()))
|
||||
Ok(Self(colorimetry.assume_init()))
|
||||
} else {
|
||||
Err(glib::glib_bool_error!("Invalid colorimetry info"))
|
||||
}
|
||||
|
@ -179,12 +179,13 @@ impl fmt::Display for crate::VideoColorimetry {
|
|||
impl str::FromStr for crate::VideoChromaSite {
|
||||
type Err = glib::error::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
unsafe {
|
||||
let chroma_site = from_glib(ffi::gst_video_chroma_from_string(s.to_glib_none().0));
|
||||
if chroma_site == crate::VideoChromaSite::empty() {
|
||||
let chroma_site: Self =
|
||||
from_glib(ffi::gst_video_chroma_from_string(s.to_glib_none().0));
|
||||
if chroma_site.is_empty() {
|
||||
Err(glib::glib_bool_error!("Invalid chroma site"))
|
||||
} else {
|
||||
Ok(chroma_site)
|
||||
|
@ -1034,7 +1035,7 @@ impl crate::VideoFieldOrder {
|
|||
impl str::FromStr for crate::VideoFieldOrder {
|
||||
type Err = glib::error::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
unsafe {
|
||||
|
@ -1066,7 +1067,7 @@ impl crate::VideoInterlaceMode {
|
|||
impl str::FromStr for crate::VideoInterlaceMode {
|
||||
type Err = glib::error::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -475,10 +475,10 @@ generic_impl!(ValidVideoTimeCode);
|
|||
impl str::FromStr for VideoTimeCode {
|
||||
type Err = glib::error::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
Option::<VideoTimeCode>::from_glib_full(ffi::gst_video_time_code_new_from_string(
|
||||
Option::<Self>::from_glib_full(ffi::gst_video_time_code_new_from_string(
|
||||
s.to_glib_none().0,
|
||||
))
|
||||
.ok_or_else(|| glib::glib_bool_error!("Failed to create VideoTimeCode from string"))
|
||||
|
|
|
@ -120,12 +120,12 @@ impl fmt::Display for VideoTimeCodeInterval {
|
|||
impl str::FromStr for VideoTimeCodeInterval {
|
||||
type Err = glib::error::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
Option::<VideoTimeCodeInterval>::from_glib_full(
|
||||
ffi::gst_video_time_code_interval_new_from_string(s.to_glib_none().0),
|
||||
)
|
||||
Option::<Self>::from_glib_full(ffi::gst_video_time_code_interval_new_from_string(
|
||||
s.to_glib_none().0,
|
||||
))
|
||||
.ok_or_else(|| {
|
||||
glib::glib_bool_error!("Failed to create VideoTimeCodeInterval from string")
|
||||
})
|
||||
|
|
|
@ -161,7 +161,7 @@ impl Caps {
|
|||
impl str::FromStr for Caps {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
Option::<_>::from_glib_full(ffi::gst_caps_from_string(s.to_glib_none().0))
|
||||
|
|
|
@ -123,7 +123,7 @@ impl fmt::Display for CapsFeatures {
|
|||
impl str::FromStr for CapsFeatures {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let ptr = ffi::gst_caps_features_from_string(s.to_glib_none().0);
|
||||
|
@ -133,7 +133,7 @@ impl str::FromStr for CapsFeatures {
|
|||
));
|
||||
}
|
||||
|
||||
Ok(CapsFeatures(ptr::NonNull::new_unchecked(
|
||||
Ok(Self(ptr::NonNull::new_unchecked(
|
||||
ptr as *mut CapsFeaturesRef,
|
||||
)))
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ impl Eq for Structure {}
|
|||
impl str::FromStr for Structure {
|
||||
type Err = glib::BoolError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, glib::BoolError> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
let structure = ffi::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut());
|
||||
|
@ -190,7 +190,7 @@ impl str::FromStr for Structure {
|
|||
"Failed to parse structure from string"
|
||||
))
|
||||
} else {
|
||||
Ok(Structure(ptr::NonNull::new_unchecked(
|
||||
Ok(Self(ptr::NonNull::new_unchecked(
|
||||
structure as *mut StructureRef,
|
||||
)))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue