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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! FBX DOM load error.

use std::{error, fmt};

use crate::tree::v7400::LoadError as TreeLoadError;

/// FBX DOM load error.
#[derive(Debug)]
pub struct LoadError(Box<dyn error::Error + Send + Sync + 'static>);

impl LoadError {
    /// Creates a new `LoadError`.
    pub(crate) fn new(e: impl Into<Box<dyn error::Error + Send + Sync + 'static>>) -> Self {
        Self(e.into())
    }
}

impl fmt::Display for LoadError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl error::Error for LoadError {
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        Some(&*self.0)
    }
}

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

/// FBX DOM structure error.
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub(crate) enum StructureError {
    /// Toplevel `Connections` node not found.
    MissingConnectionsNode,
    /// Toplevel `Documents` node not found.
    MissingDocumentsNode,
    /// Toplevel `Objects` node not found.
    MissingObjectsNode,
}

impl fmt::Display for StructureError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            StructureError::MissingConnectionsNode => {
                f.write_str("Toplevel `Connections` node not found")
            }
            StructureError::MissingDocumentsNode => {
                f.write_str("Toplevel `Documents` node not found")
            }
            StructureError::MissingObjectsNode => f.write_str("Toplevel `Objects` node not found"),
        }
    }
}

impl error::Error for StructureError {}

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