Skip to main content

cordis_loader/
error.rs

1//! Error type combining core and include failures.
2
3use cordis::CordisError;
4use cordis_include::IncludeError;
5use std::error::Error as StdError;
6use std::fmt;
7
8/// Result alias used throughout `cordis-loader`.
9pub type Result<T> = std::result::Result<T, LoaderError>;
10
11/// Errors produced while loading entries and driving fibers.
12#[derive(Debug)]
13pub enum LoaderError {
14    /// A core lifecycle or registry operation failed.
15    Cordis(CordisError),
16    /// The entry tree or config file layer failed.
17    Include(IncludeError),
18}
19
20impl fmt::Display for LoaderError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Self::Cordis(error) => write!(f, "{error}"),
24            Self::Include(error) => write!(f, "{error}"),
25        }
26    }
27}
28
29impl StdError for LoaderError {
30    fn source(&self) -> Option<&(dyn StdError + 'static)> {
31        match self {
32            Self::Cordis(error) => Some(error),
33            Self::Include(error) => Some(error),
34        }
35    }
36}
37
38impl From<CordisError> for LoaderError {
39    fn from(error: CordisError) -> Self {
40        Self::Cordis(error)
41    }
42}
43
44impl From<IncludeError> for LoaderError {
45    fn from(error: IncludeError) -> Self {
46        Self::Include(error)
47    }
48}