use core::fmt;
use core::convert::Infallible;
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Unspecified;
impl fmt::Display for Unspecified {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Unspecified")
}
}
std! { impl std::error::Error for Unspecified {} }
no_std_io! {
impl embedded_io::Error for Unspecified {
fn kind(&self) -> embedded_io::ErrorKind {
embedded_io::ErrorKind::Other
}
}
}
impl From<crate::buf::InvalidSize> for Unspecified {
#[inline]
fn from(_value: crate::buf::InvalidSize) -> Self { Self }
}
impl From<Infallible> for Unspecified {
#[inline]
fn from(_value: Infallible) -> Self { Self }
}
#[derive(Debug, Copy, Clone)]
pub struct InvalidIters;
impl fmt::Display for InvalidIters {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("InvalidIters")
}
}
std! {
impl std::error::Error for InvalidIters {}
}
impl From<InvalidIters> for Unspecified {
#[inline]
fn from(_value: InvalidIters) -> Self { Self }
}
#[allow(clippy::missing_errors_doc)]
pub trait MakeOpaque<T> {
fn opaque(self) -> Result<T, Unspecified>;
fn opaque_bind<F: FnOnce(T) -> Result<N, NE>, N, NE>(self, op: F) -> Result<N, Unspecified>;
fn opaque_map<F: FnOnce(T) -> N, N>(self, op: F) -> Result<N, Unspecified>;
}
#[allow(clippy::option_if_let_else)]
impl<T, E> MakeOpaque<T> for Result<T, E> {
#[inline]
fn opaque(self) -> Result<T, Unspecified> {
match self {
Ok(ok) => Ok(ok),
Err(_) => Err(Unspecified)
}
}
#[inline]
fn opaque_bind<F: FnOnce(T) -> Result<N, NE>, N, NE>(self, op: F) -> Result<N, Unspecified> {
match self {
Ok(ok) => op(ok).opaque(),
Err(_) => Err(Unspecified)
}
}
#[inline]
fn opaque_map<F: FnOnce(T) -> N, N>(self, op: F) -> Result<N, Unspecified> {
match self {
Ok(ok) => Ok(op(ok)),
Err(_) => Err(Unspecified)
}
}
}