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
69
70
71
72
73
74
75
//! Error type for `oxideav-mesh3d`.
//!
//! Under the default `registry` feature this is a re-export of
//! [`oxideav_core::Error`] / [`oxideav_core::Result`] so format
//! crates and downstream consumers share one error vocabulary across
//! the framework. With `--no-default-features` we fall back to a
//! crate-local enum that mirrors the relevant variants — enough for
//! decoders/encoders to report invalid input or unsupported features
//! without dragging in `oxideav-core`.
#[cfg(feature = "registry")]
pub use oxideav_core::{Error, Result};
#[cfg(not(feature = "registry"))]
mod standalone {
use std::fmt;
/// Crate-local error type used when the `registry` feature is off.
#[derive(Debug)]
pub enum Error {
/// Bytes don't match what the decoder expected.
InvalidData(String),
/// Spec construct that this crate or format doesn't yet handle.
Unsupported(String),
/// I/O failure while reading or writing.
Io(std::io::Error),
/// Catch-all for ad-hoc error messages.
Other(String),
}
impl Error {
pub fn invalid(msg: impl Into<String>) -> Self {
Self::InvalidData(msg.into())
}
pub fn unsupported(msg: impl Into<String>) -> Self {
Self::Unsupported(msg.into())
}
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidData(s) => write!(f, "invalid data: {s}"),
Self::Unsupported(s) => write!(f, "unsupported: {s}"),
Self::Io(e) => write!(f, "I/O error: {e}"),
Self::Other(s) => write!(f, "{s}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;
}
#[cfg(not(feature = "registry"))]
pub use standalone::{Error, Result};