From a4f25df045801f19a575e77b5c75325c5188be37 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Sun, 28 Oct 2018 17:40:00 +0000 Subject: [PATCH] enums: Implement the From trait for error/success This implements the From trait for all *Error/*Success enums to the corresponding *Return enum. --- gstreamer/src/enums.rs | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/gstreamer/src/enums.rs b/gstreamer/src/enums.rs index f124df683..1d84cbd2a 100644 --- a/gstreamer/src/enums.rs +++ b/gstreamer/src/enums.rs @@ -47,6 +47,12 @@ pub enum StateChangeSuccess { NoPreroll, } +impl From for StateChangeReturn { + fn from(value: StateChangeSuccess) -> Self { + StateChangeReturn::from_ok(value) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[must_use] pub struct StateChangeError; @@ -57,6 +63,12 @@ impl fmt::Display for StateChangeError { } } +impl From for StateChangeReturn { + fn from(value: StateChangeError) -> Self { + StateChangeReturn::from_error(value) + } +} + impl Error for StateChangeError { fn description(&self) -> &str { "Element failed to change its state" @@ -115,6 +127,12 @@ pub enum FlowSuccess { Ok, } +impl From for FlowReturn { + fn from(value: FlowSuccess) -> Self { + FlowReturn::from_ok(value) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[must_use] pub enum FlowError { @@ -135,6 +153,12 @@ impl fmt::Display for FlowError { } } +impl From for FlowReturn { + fn from(value: FlowError) -> Self { + FlowReturn::from_error(value) + } +} + impl Error for FlowError { fn description(&self) -> &str { match *self { @@ -188,6 +212,12 @@ impl PadLinkReturn { #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub struct PadLinkSuccess; +impl From for PadLinkReturn { + fn from(value: PadLinkSuccess) -> Self { + PadLinkReturn::from_ok(value) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[must_use] pub enum PadLinkError { @@ -205,6 +235,12 @@ impl fmt::Display for PadLinkError { } } +impl From for PadLinkReturn { + fn from(value: PadLinkError) -> Self { + PadLinkReturn::from_error(value) + } +} + impl Error for PadLinkError { fn description(&self) -> &str { match *self { @@ -258,6 +294,12 @@ pub enum ClockSuccess { Done, } +impl From for ClockReturn { + fn from(value: ClockSuccess) -> Self { + ClockReturn::from_ok(value) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[must_use] pub enum ClockError { @@ -275,6 +317,12 @@ impl fmt::Display for ClockError { } } +impl From for ClockReturn { + fn from(value: ClockError) -> Self { + ClockReturn::from_error(value) + } +} + impl Error for ClockError { fn description(&self) -> &str { match *self {