fbxcel_dom/any/
error.rs

1//! Error and result types for `tree::any` module.
2
3use std::{error, fmt};
4
5use fbxcel::{low::FbxVersion, tree};
6
7/// AnyTree load result.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Error.
11#[derive(Debug)]
12#[non_exhaustive]
13pub enum Error {
14    /// Unknown FBX parser.
15    ///
16    /// This means that the FBX version may be supported by the backend parser, but the backend
17    /// parser used to load the document is unsupported by fbxcel-dom crate.
18    UnsupportedVersion(FbxVersion),
19    /// Tree load error.
20    Tree(tree::any::Error),
21    /// DOM load error.
22    Dom(Box<dyn error::Error + Send + Sync + 'static>),
23}
24
25impl error::Error for Error {
26    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
27        match self {
28            Error::Tree(e) => Some(e),
29            Error::Dom(e) => Some(&**e),
30            Error::UnsupportedVersion(..) => None,
31        }
32    }
33}
34
35impl fmt::Display for Error {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        match self {
38            Error::Tree(e) => write!(f, "Tree load error: {}", e),
39            Error::Dom(e) => write!(f, "DOM document load error: {}", e),
40            Error::UnsupportedVersion(ver) => write!(f, "Unsupported FBX version: {:?}", ver),
41        }
42    }
43}
44
45impl From<tree::any::Error> for Error {
46    fn from(e: tree::any::Error) -> Self {
47        Error::Tree(e)
48    }
49}
50
51impl From<crate::v7400::LoadError> for Error {
52    fn from(e: crate::v7400::LoadError) -> Self {
53        Error::Dom(e.into())
54    }
55}