base64_simd/
error.rs

1use core::fmt;
2
3/// Base64 Error
4pub struct Error(());
5
6impl Error {
7    #[inline(always)]
8    pub(crate) const fn new() -> Self {
9        Error(())
10    }
11}
12
13impl fmt::Debug for Error {
14    #[inline]
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        <str as fmt::Debug>::fmt("Base64Error", f)
17    }
18}
19
20impl fmt::Display for Error {
21    #[inline]
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        <str as fmt::Display>::fmt("Base64Error", f)
24    }
25}
26
27#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
28#[cfg(feature = "std")]
29impl std::error::Error for Error {}
30
31macro_rules! ensure {
32    ($cond:expr) => {
33        if !$cond {
34            return Err($crate::error::Error::new());
35        }
36    };
37}
38
39#[allow(unused_macros)]
40macro_rules! try_ {
41    ($result:expr) => {
42        match $result {
43            Ok(value) => value,
44            Err(_) => return Err(Error::new()),
45        }
46    };
47}