diff --git a/examples/src/bin/cairo_compositor.rs b/examples/src/bin/cairo_compositor.rs index dfea82a87..276005587 100644 --- a/examples/src/bin/cairo_compositor.rs +++ b/examples/src/bin/cairo_compositor.rs @@ -422,7 +422,7 @@ mod cairo_compositor { impl CairoCompositor { // Creates a new instance of our compositor with the given name. pub fn new(name: Option<&str>) -> Self { - glib::Object::new(&[("name", &name)]).expect("Failed to create cairo compositor") + glib::Object::new(&[("name", &name)]) } } diff --git a/examples/src/bin/fd_allocator.rs b/examples/src/bin/fd_allocator.rs index 88ef1a513..c730b1d4f 100644 --- a/examples/src/bin/fd_allocator.rs +++ b/examples/src/bin/fd_allocator.rs @@ -52,7 +52,7 @@ fn create_receiver_pipeline( let pipeline = gst::Pipeline::new(None); let src = gst::ElementFactory::make("appsrc", None).map_err(|_| MissingElement("appsrc"))?; - let filter = video_filter::FdMemoryFadeInVideoFilter::new()?.upcast::(); + let filter = video_filter::FdMemoryFadeInVideoFilter::default().upcast::(); let convert = gst::ElementFactory::make("videoconvert", None) .map_err(|_| MissingElement("videoconvert"))?; let queue = gst::ElementFactory::make("queue", None).map_err(|_| MissingElement("queue"))?; @@ -376,15 +376,13 @@ fn main() { // The purpose of this custom video filter is to demonstrate how // the file descriptor of a FdMemory can be accessed. mod video_filter { - use anyhow::Error; - glib::wrapper! { pub struct FdMemoryFadeInVideoFilter(ObjectSubclass) @extends gst_video::VideoFilter, gst_base::BaseTransform, gst::Element, gst::Object; } - impl FdMemoryFadeInVideoFilter { - pub fn new() -> Result { - Ok(glib::Object::builder().build()?) + impl Default for FdMemoryFadeInVideoFilter { + fn default() -> Self { + glib::Object::builder().build() } } mod imp { diff --git a/examples/src/bin/glfilter.rs b/examples/src/bin/glfilter.rs index 53d1b911f..761572776 100644 --- a/examples/src/bin/glfilter.rs +++ b/examples/src/bin/glfilter.rs @@ -52,7 +52,7 @@ mod mirror { impl GLMirrorFilter { pub fn new(name: Option<&str>) -> Self { - glib::Object::new(&[("name", &name)]).expect("Failed to create GL Mirror Filter Object") + glib::Object::new(&[("name", &name)]) } } diff --git a/examples/src/bin/rtsp-server-subclass.rs b/examples/src/bin/rtsp-server-subclass.rs index 3b24e8d29..db5ffa1ed 100644 --- a/examples/src/bin/rtsp-server-subclass.rs +++ b/examples/src/bin/rtsp-server-subclass.rs @@ -153,7 +153,7 @@ mod media_factory { impl Default for Factory { // Creates a new instance of our factory fn default() -> Factory { - glib::Object::new(&[]).expect("Failed to create factory") + glib::Object::new(&[]) } } } @@ -265,7 +265,7 @@ mod server { impl Default for Server { // Creates a new instance of our factory fn default() -> Server { - glib::Object::new(&[]).expect("Failed to create server") + glib::Object::new(&[]) } } } @@ -313,7 +313,7 @@ mod client { impl Default for Client { // Creates a new instance of our factory fn default() -> Client { - glib::Object::new(&[]).expect("Failed to create client") + glib::Object::new(&[]) } } } @@ -361,7 +361,7 @@ mod mount_points { impl Default for MountPoints { // Creates a new instance of our factory fn default() -> Self { - glib::Object::new(&[]).expect("Failed to create mount points") + glib::Object::new(&[]) } } } diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index c552d9529..33cb610d2 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -223,7 +223,7 @@ mod fir_filter { impl FirFilter { // Creates a new instance of our filter with the given name pub fn new(name: Option<&str>) -> FirFilter { - glib::Object::new(&[("name", &name)]).expect("Failed to create fir filter") + glib::Object::new(&[("name", &name)]) } // Sets the coefficients by getting access to the private diff --git a/gstreamer/src/child_proxy.rs b/gstreamer/src/child_proxy.rs index acb67f6e8..44c3c82e0 100644 --- a/gstreamer/src/child_proxy.rs +++ b/gstreamer/src/child_proxy.rs @@ -15,32 +15,11 @@ pub trait ChildProxyExtManual: 'static { #[doc(alias = "get_child_property")] #[doc(alias = "gst_child_proxy_get")] fn child_property_value(&self, name: &str) -> glib::Value; - #[doc(alias = "get_child_property")] - #[doc(alias = "gst_child_proxy_get")] - fn try_child_property glib::value::FromValue<'b> + 'static>( - &self, - name: &str, - ) -> Result; - #[doc(alias = "get_child_property")] - #[doc(alias = "gst_child_proxy_get")] - fn try_child_property_value(&self, name: &str) -> Result; #[doc(alias = "gst_child_proxy_set")] fn set_child_property(&self, name: &str, value: V); #[doc(alias = "gst_child_proxy_set_property")] fn set_child_property_from_value(&self, name: &str, value: &glib::Value); - #[doc(alias = "gst_child_proxy_set")] - fn try_set_child_property( - &self, - name: &str, - value: V, - ) -> Result<(), glib::BoolError>; - #[doc(alias = "gst_child_proxy_set_property")] - fn try_set_child_property_from_value( - &self, - name: &str, - value: &glib::Value, - ) -> Result<(), glib::BoolError>; } impl> ChildProxyExtManual for O { @@ -62,54 +41,27 @@ impl> ChildProxyExtManual for O { } } + #[track_caller] fn child_property glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V { let (child, pspec) = self.lookup(name).unwrap(); child.property(pspec.name()) } + #[track_caller] fn child_property_value(&self, name: &str) -> glib::Value { let (child, pspec) = self.lookup(name).unwrap(); child.property_value(pspec.name()) } - fn try_child_property glib::value::FromValue<'b> + 'static>( - &self, - name: &str, - ) -> Result { - let (child, pspec) = self.lookup(name)?; - child.try_property(pspec.name()) - } - - fn try_child_property_value(&self, name: &str) -> Result { - let (child, pspec) = self.lookup(name)?; - child.try_property_value(pspec.name()) - } - + #[track_caller] fn set_child_property(&self, name: &str, value: V) { let (child, pspec) = self.lookup(name).unwrap(); child.set_property(pspec.name(), value) } + #[track_caller] fn set_child_property_from_value(&self, name: &str, value: &glib::Value) { let (child, pspec) = self.lookup(name).unwrap(); child.set_property_from_value(pspec.name(), value) } - - fn try_set_child_property( - &self, - name: &str, - value: V, - ) -> Result<(), glib::BoolError> { - let (child, pspec) = self.lookup(name)?; - child.try_set_property(pspec.name(), value) - } - - fn try_set_child_property_from_value( - &self, - name: &str, - value: &glib::Value, - ) -> Result<(), glib::BoolError> { - let (child, pspec) = self.lookup(name)?; - child.try_set_property_from_value(pspec.name(), value) - } } diff --git a/gstreamer/src/gobject.rs b/gstreamer/src/gobject.rs index 30d8de4d5..e80e2f47e 100644 --- a/gstreamer/src/gobject.rs +++ b/gstreamer/src/gobject.rs @@ -4,18 +4,16 @@ use crate::value::GstValueExt; use glib::prelude::*; pub trait GObjectExtManualGst: 'static { - #[doc(alias = "gst_util_set_object_arg")] - fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError>; - #[doc(alias = "gst_util_set_object_arg")] fn set_property_from_str(&self, name: &str, value: &str); } impl> GObjectExtManualGst for O { - fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError> { - let pspec = self.find_property(name).ok_or_else(|| { - glib::bool_error!("property '{}' of type '{}' not found", name, self.type_()) - })?; + #[track_caller] + fn set_property_from_str(&self, name: &str, value: &str) { + let pspec = self.find_property(name).unwrap_or_else(|| { + panic!("property '{}' of type '{}' not found", name, self.type_()); + }); let value = { if pspec.value_type() == crate::Structure::static_type() && value == "NULL" { @@ -23,20 +21,16 @@ impl> GObjectExtManualGst for O { } else { #[cfg(feature = "v1_20")] { - glib::Value::deserialize_with_pspec(value, &pspec)? + glib::Value::deserialize_with_pspec(value, &pspec).unwrap() } #[cfg(not(feature = "v1_20"))] { - glib::Value::deserialize(value, pspec.value_type())? + glib::Value::deserialize(value, pspec.value_type()).unwrap() } } }; - self.try_set_property_from_value(name, &value) - } - - fn set_property_from_str(&self, name: &str, value: &str) { - self.try_set_property_from_str(name, value).unwrap() + self.set_property_from_value(name, &value) } } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 1223a59dd..7bc93e705 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -1661,8 +1661,7 @@ impl + IsA + glib::object::IsClass> PadBuilder { pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self { assert_initialized_main_thread!(); - let pad = glib::Object::new::(&[("name", &name), ("direction", &direction)]) - .expect("Failed to create pad"); + let pad = glib::Object::new::(&[("name", &name), ("direction", &direction)]); // Ghost pads are a bit special if let Some(pad) = pad.dynamic_cast_ref::() { @@ -1713,7 +1712,6 @@ impl + IsA + glib::object::IsClass> PadBuilder { ("template", templ), ], ) - .expect("Failed to create pad") .downcast::() .unwrap(); diff --git a/gstreamer/src/subclass/buffer_pool.rs b/gstreamer/src/subclass/buffer_pool.rs index e90740901..ca39891b5 100644 --- a/gstreamer/src/subclass/buffer_pool.rs +++ b/gstreamer/src/subclass/buffer_pool.rs @@ -554,7 +554,7 @@ mod tests { impl Default for TestBufferPool { fn default() -> Self { - glib::Object::new(&[]).unwrap() + glib::Object::new(&[]) } } diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index 54a67ece1..c6df35efa 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -782,7 +782,7 @@ mod tests { impl TestElement { pub fn new(name: Option<&str>) -> Self { - glib::Object::new(&[("name", &name)]).unwrap() + glib::Object::new(&[("name", &name)]) } } diff --git a/gstreamer/src/subclass/pad.rs b/gstreamer/src/subclass/pad.rs index 1cc32afd5..0b0d24b9a 100644 --- a/gstreamer/src/subclass/pad.rs +++ b/gstreamer/src/subclass/pad.rs @@ -131,7 +131,7 @@ mod tests { impl TestPad { pub fn new(name: &str, direction: PadDirection) -> Self { - glib::Object::new(&[("name", &name), ("direction", &direction)]).unwrap() + glib::Object::new(&[("name", &name), ("direction", &direction)]) } } diff --git a/gstreamer/src/subclass/task_pool.rs b/gstreamer/src/subclass/task_pool.rs index f6e556559..e8bc31b91 100644 --- a/gstreamer/src/subclass/task_pool.rs +++ b/gstreamer/src/subclass/task_pool.rs @@ -313,7 +313,7 @@ mod tests { impl Default for TestPool { fn default() -> Self { - glib::Object::new(&[]).unwrap() + glib::Object::new(&[]) } } diff --git a/tutorials/src/bin/basic-tutorial-13.rs b/tutorials/src/bin/basic-tutorial-13.rs index 7ad59e67d..3154e0ce4 100644 --- a/tutorials/src/bin/basic-tutorial-13.rs +++ b/tutorials/src/bin/basic-tutorial-13.rs @@ -56,7 +56,7 @@ fn send_seek_event(pipeline: &Element, rate: f64) -> bool { }; // If we have not done so, obtain the sink through which we will send the seek events - if let Ok(Some(video_sink)) = pipeline.try_property::>("video-sink") { + if let Some(video_sink) = pipeline.property::>("video-sink") { println!("Current rate: {}\r", rate); // Send the event video_sink.send_event(seek_event) @@ -171,8 +171,7 @@ USAGE: Choose one of the following options, then press enter: } } Command::NextFrame => { - if let Ok(Some(video_sink)) = pipeline.try_property::>("video-sink") - { + if let Some(video_sink) = pipeline.property::>("video-sink") { // Send the event let step = Step::new(gst::format::Buffers(1), rate.abs(), true, false); video_sink.send_event(step);