use zb_zcl::Status as ZclStatus;
use zb_zdp::Status as ZdpStatus;
use crate::Error;
pub trait StatusExt {
fn ensure_success(self) -> Result<(), Error>;
}
impl StatusExt for ZclStatus {
fn ensure_success(self) -> Result<(), Error> {
match self {
Self::Success => Ok(()),
other => Err(Ok(other).into()),
}
}
}
impl StatusExt for Result<ZclStatus, u8> {
fn ensure_success(self) -> Result<(), Error> {
match self {
Ok(ZclStatus::Success) => Ok(()),
other => Err(other.into()),
}
}
}
impl StatusExt for ZdpStatus {
fn ensure_success(self) -> Result<(), Error> {
match self {
Self::Success => Ok(()),
other => Err(Ok(other).into()),
}
}
}
impl StatusExt for Result<ZdpStatus, u8> {
fn ensure_success(self) -> Result<(), Error> {
match self {
Ok(ZdpStatus::Success) => Ok(()),
other => Err(other.into()),
}
}
}