enums: Implement the From trait for error/success

This implements the From trait for all *Error/*Success enums to the
corresponding *Return enum.
This commit is contained in:
Arun Raghavan 2018-10-28 17:40:00 +00:00 committed by Sebastian Dröge
parent 6325e0fcce
commit a4f25df045

View file

@ -47,6 +47,12 @@ pub enum StateChangeSuccess {
NoPreroll,
}
impl From<StateChangeSuccess> 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<StateChangeError> 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<FlowSuccess> 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<FlowError> 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<PadLinkSuccess> 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<PadLinkError> 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<ClockSuccess> 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<ClockError> for ClockReturn {
fn from(value: ClockError) -> Self {
ClockReturn::from_error(value)
}
}
impl Error for ClockError {
fn description(&self) -> &str {
match *self {