examples: Move out from 'failure' crate as it is deprecated

The 'failure' crate has been stale for quite some time and better
alternatives has been developed since its introduction. We choose the
'anyhow' and 'derive_more' to replace it.
This commit is contained in:
Otavio Salvador 2020-05-02 20:23:38 -03:00
parent 6fc70ee6b6
commit 2022890766
18 changed files with 150 additions and 196 deletions

View file

@ -23,10 +23,10 @@ gstreamer-rtsp-server-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gs
gtk = { git = "https://github.com/gtk-rs/gtk", optional = true } gtk = { git = "https://github.com/gtk-rs/gtk", optional = true }
gdk = { git = "https://github.com/gtk-rs/gdk", optional = true } gdk = { git = "https://github.com/gtk-rs/gdk", optional = true }
gio = { git = "https://github.com/gtk-rs/gio", optional = true } gio = { git = "https://github.com/gtk-rs/gio", optional = true }
anyhow = "1.0"
derive_more = "0.99.5"
futures = "0.3" futures = "0.3"
byte-slice-cast = "0.3" byte-slice-cast = "0.3"
failure = "0.1"
failure_derive = "0.1"
cairo-rs = { git = "https://github.com/gtk-rs/cairo", features=["use_glib"], optional = true } cairo-rs = { git = "https://github.com/gtk-rs/cairo", features=["use_glib"], optional = true }
pango = { git = "https://github.com/gtk-rs/pango", optional = true } pango = { git = "https://github.com/gtk-rs/pango", optional = true }
pangocairo = { git = "https://github.com/gtk-rs/pangocairo", optional = true } pangocairo = { git = "https://github.com/gtk-rs/pangocairo", optional = true }

View file

@ -21,27 +21,23 @@ use byte_slice_cast::*;
use std::i16; use std::i16;
use std::i32; use std::i32;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
fn create_pipeline() -> Result<gst::Pipeline, Error> { fn create_pipeline() -> Result<gst::Pipeline, Error> {
@ -162,7 +158,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -15,27 +15,23 @@ use gst::prelude::*;
extern crate gstreamer_app as gst_app; extern crate gstreamer_app as gst_app;
extern crate gstreamer_video as gst_video; extern crate gstreamer_video as gst_video;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
const WIDTH: usize = 320; const WIDTH: usize = 320;
@ -154,7 +150,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -43,27 +43,23 @@ use std::env;
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
@ -272,7 +268,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()), .into()),
}?; }?;
@ -286,7 +282,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -16,17 +16,17 @@ use crate::pbutils::prelude::*;
use crate::pbutils::DiscovererInfo; use crate::pbutils::DiscovererInfo;
use crate::pbutils::DiscovererStreamInfo; use crate::pbutils::DiscovererStreamInfo;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
use std::env; use std::env;
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Discoverer error {}", _0)] #[display(fmt = "Discoverer error {}", _0)]
struct DiscovererError(&'static str); struct DiscovererError(#[error(not(source))] &'static str);
fn print_tags(info: &DiscovererInfo) { fn print_tags(info: &DiscovererInfo) {
println!("Tags:"); println!("Tags:");

View file

@ -29,27 +29,23 @@ use std::env;
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
@ -302,7 +298,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()), .into()),
}?; }?;
@ -316,7 +312,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -47,9 +47,6 @@ use std::env;
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[allow(unused_imports)]
use failure::Error;
fn main_loop(uri: &str) -> Result<(), glib::BoolError> { fn main_loop(uri: &str) -> Result<(), glib::BoolError> {
ges::init()?; ges::init()?;

View file

@ -18,27 +18,23 @@ use std::mem;
use std::ptr; use std::ptr;
use std::sync::mpsc; use std::sync::mpsc;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
#[rustfmt::skip] #[rustfmt::skip]
@ -587,7 +583,7 @@ impl App {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }
@ -684,7 +680,7 @@ fn main_loop(mut app: App) -> Result<glutin::WindowedContext<glutin::PossiblyCur
fn cleanup( fn cleanup(
_windowed_context: glutin::WindowedContext<glutin::PossiblyCurrent>, _windowed_context: glutin::WindowedContext<glutin::PossiblyCurrent>,
) -> Result<(), failure::Error> { ) -> Result<(), Error> {
// To ensure that the context stays alive longer than the pipeline or any reference // To ensure that the context stays alive longer than the pipeline or any reference
// inside GStreamer to the GL context, its display or anything else. See // inside GStreamer to the GL context, its display or anything else. See
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/196 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/196

View file

@ -20,27 +20,23 @@ use pango::prelude::*;
use std::ops; use std::ops;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
struct DrawingContext { struct DrawingContext {
@ -247,7 +243,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -13,8 +13,7 @@ extern crate gstreamer_player as gst_player;
use std::env; use std::env;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
#[allow(unused_imports)] use anyhow::Error;
use failure::Error;
#[allow(unused_imports)] #[allow(unused_imports)]
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]

View file

@ -7,36 +7,32 @@ use std::env;
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "No such pad {} in {}", _0, _1)] #[display(fmt = "No such pad {} in {}", _0, _1)]
struct NoSuchPad(&'static str, String); struct NoSuchPad(#[error(not(source))] &'static str, String);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Unknown payload type {}", _0)] #[display(fmt = "Unknown payload type {}", _0)]
struct UnknownPT(u32); struct UnknownPT(#[error(not(source))] u32);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Usage: {} (play | record) DROP_PROBABILITY", _0)] #[display(fmt = "Usage: {} (play | record) DROP_PROBABILITY", _0)]
struct UsageError(String); struct UsageError(#[error(not(source))] String);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
fn make_element( fn make_element(
@ -270,7 +266,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -7,32 +7,28 @@ mod examples_common;
use std::env; use std::env;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "No such pad {} in {}", _0, _1)] #[display(fmt = "No such pad {} in {}", _0, _1)]
struct NoSuchPad(&'static str, String); struct NoSuchPad(&'static str, String);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Usage: {} URI FEC_PERCENTAGE", _0)] #[display(fmt = "Usage: {} URI FEC_PERCENTAGE", _0)]
struct UsageError(String); struct UsageError(#[error(not(source))] String);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
fn make_element( fn make_element(
@ -192,7 +188,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -9,8 +9,6 @@ extern crate gstreamer_rtsp as gst_rtsp;
extern crate gstreamer_rtsp_server as gst_rtsp_server; extern crate gstreamer_rtsp_server as gst_rtsp_server;
extern crate gstreamer_rtsp_server_sys as gst_rtsp_server_sys; extern crate gstreamer_rtsp_server_sys as gst_rtsp_server_sys;
use failure::Error;
use failure::Fail;
use std::env; use std::env;
use std::ptr; use std::ptr;
@ -19,16 +17,19 @@ use gst_rtsp::*;
use gst_rtsp_server::prelude::*; use gst_rtsp_server::prelude::*;
use gst_rtsp_server::*; use gst_rtsp_server::*;
use anyhow::Error;
use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Could not get mount points")] #[display(fmt = "Could not get mount points")]
struct NoMountPoints; struct NoMountPoints;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Usage: {} LAUNCH_LINE", _0)] #[display(fmt = "Usage: {} LAUNCH_LINE", _0)]
struct UsageError(String); struct UsageError(#[error(not(source))] String);
fn main_loop() -> Result<(), Error> { fn main_loop() -> Result<(), Error> {
let args: Vec<_> = env::args().collect(); let args: Vec<_> = env::args().collect();

View file

@ -19,19 +19,19 @@ use glib::glib_object_subclass;
use glib::glib_object_wrapper; use glib::glib_object_wrapper;
use glib::glib_wrapper; use glib::glib_wrapper;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Could not get mount points")] #[display(fmt = "Could not get mount points")]
struct NoMountPoints; struct NoMountPoints;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Usage: {} LAUNCH_LINE", _0)] #[display(fmt = "Usage: {} LAUNCH_LINE", _0)]
struct UsageError(String); struct UsageError(#[error(not(source))] String);
fn main_loop() -> Result<(), Error> { fn main_loop() -> Result<(), Error> {
let main_loop = glib::MainLoop::new(None, false); let main_loop = glib::MainLoop::new(None, false);

View file

@ -10,19 +10,19 @@ extern crate gstreamer as gst;
extern crate gstreamer_rtsp_server as gst_rtsp_server; extern crate gstreamer_rtsp_server as gst_rtsp_server;
use gst_rtsp_server::prelude::*; use gst_rtsp_server::prelude::*;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Could not get mount points")] #[display(fmt = "Could not get mount points")]
struct NoMountPoints; struct NoMountPoints;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Usage: {} LAUNCH_LINE", _0)] #[display(fmt = "Usage: {} LAUNCH_LINE", _0)]
struct UsageError(String); struct UsageError(#[error(not(source))] String);
fn main_loop() -> Result<(), Error> { fn main_loop() -> Result<(), Error> {
let args: Vec<_> = env::args().collect(); let args: Vec<_> = env::args().collect();

View file

@ -17,8 +17,8 @@ use gst::gst_info;
use gst::gst_trace; use gst::gst_trace;
use gst::prelude::*; use gst::prelude::*;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
@ -294,21 +294,17 @@ mod fir_filter {
} }
} }
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
fn create_pipeline() -> Result<gst::Pipeline, Error> { fn create_pipeline() -> Result<gst::Pipeline, Error> {
@ -384,7 +380,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -21,27 +21,24 @@
extern crate gstreamer as gst; extern crate gstreamer as gst;
use gst::prelude::*; use gst::prelude::*;
use failure::Error; use anyhow::anyhow;
use failure::Fail; use anyhow::Error;
use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(String); struct MissingElement(#[error(not(source))] String);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
fn example_main() -> Result<(), Error> { fn example_main() -> Result<(), Error> {
@ -66,16 +63,16 @@ fn example_main() -> Result<(), Error> {
let pipeline = pipeline let pipeline = pipeline
.downcast::<gst::Pipeline>() .downcast::<gst::Pipeline>()
.map_err(|_| failure::err_msg("Generated pipeline is no pipeline"))?; .map_err(|_| anyhow!("Generated pipeline is no pipeline"))?;
// Query the pipeline for elements implementing the GstTagsetter interface. // Query the pipeline for elements implementing the GstTagsetter interface.
// In our case, this will return the flacenc element. // In our case, this will return the flacenc element.
let tagsetter = pipeline let tagsetter = pipeline
.get_by_interface(gst::TagSetter::static_type()) .get_by_interface(gst::TagSetter::static_type())
.ok_or_else(|| failure::err_msg("No TagSetter found"))?; .ok_or_else(|| anyhow!("No TagSetter found"))?;
let tagsetter = tagsetter let tagsetter = tagsetter
.dynamic_cast::<gst::TagSetter>() .dynamic_cast::<gst::TagSetter>()
.map_err(|_| failure::err_msg("No TagSetter found"))?; .map_err(|_| anyhow!("No TagSetter found"))?;
// Tell the element implementing the GstTagsetter interface how to handle already existing // Tell the element implementing the GstTagsetter interface how to handle already existing
// metadata. // metadata.
@ -103,7 +100,7 @@ fn example_main() -> Result<(), Error> {
.to_string(), .to_string(),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }

View file

@ -23,27 +23,23 @@ use gst::prelude::*;
use std::env; use std::env;
use failure::Error; use anyhow::Error;
use failure::Fail; use derive_more::{Display, Error};
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail(display = "Missing element {}", _0)] #[display(fmt = "Missing element {}", _0)]
struct MissingElement(&'static str); struct MissingElement(#[error(not(source))] &'static str);
#[derive(Debug, Fail)] #[derive(Debug, Display, Error)]
#[fail( #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
display = "Received error from {}: {} (debug: {:?})",
src, error, debug
)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: String,
error: String, error: String,
debug: Option<String>, debug: Option<String>,
#[cause] source: glib::Error,
cause: glib::Error,
} }
fn example_main() -> Result<(), Error> { fn example_main() -> Result<(), Error> {
@ -170,7 +166,7 @@ fn example_main() -> Result<(), Error> {
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| String::from("None")),
error: err.get_error().to_string(), error: err.get_error().to_string(),
debug: err.get_debug(), debug: err.get_debug(),
cause: err.get_error(), source: err.get_error(),
} }
.into()); .into());
} }