From bbf6009c0c55edc363e2f119f3b7ca7c8d51f751 Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Wed, 20 Apr 2022 14:45:10 -0700 Subject: [PATCH] Implement Error for error types (#1) --- Cargo.toml | 1 + src/file.rs | 11 +++-------- src/video_stream.rs | 4 +++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 95ab623..f8a21aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ gstreamer = "0.16.2" gstreamer-app = "0.16.0" gstreamer-video = "0.16.0" log = "0.4" +thiserror = "1" diff --git a/src/file.rs b/src/file.rs index 4fe0833..0251e90 100644 --- a/src/file.rs +++ b/src/file.rs @@ -38,13 +38,8 @@ impl IntoIterator for FileSource { } } -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum CaptureError { - IoError(io::Error), -} - -impl From for CaptureError { - fn from(err: io::Error) -> Self { - CaptureError::IoError(err) - } + #[error("IO error: {0}")] + IoError(#[from] io::Error), } diff --git a/src/video_stream.rs b/src/video_stream.rs index 9016448..11d17cc 100644 --- a/src/video_stream.rs +++ b/src/video_stream.rs @@ -33,9 +33,11 @@ pub struct GstErrorMessage { pub source: glib::Error, } -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum StreamError { + #[error("GST error: {0:?}")] GstError(GstErrorMessage), + #[error("frame capture error")] FrameCaptureError, }