eryon_mem/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: @FL03
4*/
5
6/// a type alias for a [Result] equipped with a [MemoryError]
7pub(crate) type Result<T> = core::result::Result<T, MemoryError>;
8
9/// The [`MemoryError`] implementation enumerates the various errors handled by the memory
10/// module.
11#[derive(Debug, thiserror::Error)]
12pub enum MemoryError {
13    #[error(transparent)]
14    CoreError(#[from] eryon::Error),
15    #[cfg(feature = "serde")]
16    #[error(transparent)]
17    DeserializeError(#[from] serde::de::value::Error),
18    #[error(transparent)]
19    FmtError(#[from] core::fmt::Error),
20    #[cfg(feature = "std")]
21    #[error(transparent)]
22    IOError(#[from] std::io::Error),
23    #[cfg(feature = "serde_json")]
24    #[error(transparent)]
25    JsonError(#[from] serde_json::Error),
26}
27// #[cfg(feature = "alloc")]
28impl From<MemoryError> for eryon::Error {
29    fn from(err: MemoryError) -> Self {
30        match err {
31            MemoryError::CoreError(e) => e,
32            _ => eryon::Error::BoxError(Box::new(err)),
33        }
34    }
35}
36
37#[cfg(feature = "std")]
38impl From<&str> for MemoryError {
39    fn from(s: &str) -> Self {
40        eryon::Error::from(s).into()
41    }
42}
43
44#[cfg(feature = "std")]
45impl From<String> for MemoryError {
46    fn from(s: String) -> Self {
47        eryon::Error::from(s).into()
48    }
49}