1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Error types.

use std::{error, fmt};

use crate::pull_parser::Error as ParserError;

/// FBX data tree load error.
#[derive(Debug)]
#[non_exhaustive]
pub enum LoadError {
    /// Bad parser.
    ///
    /// This error will be mainly caused by user logic error.
    BadParser,
    /// Parser error.
    Parser(ParserError),
}

impl fmt::Display for LoadError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            LoadError::BadParser => f.write_str("Attempt to use a bad parser"),
            LoadError::Parser(e) => write!(f, "Parser error: {}", e),
        }
    }
}

impl error::Error for LoadError {
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            LoadError::Parser(e) => Some(e),
            _ => None,
        }
    }
}

impl From<ParserError> for LoadError {
    fn from(e: ParserError) -> Self {
        LoadError::Parser(e)
    }
}