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
/// A type alias for handling errors throughout meshopt
pub type Result<T> = std::result::Result<T, Error>;
/// An error that can occur
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
/// An error that occurred interfacing with native code through FFI.
#[error("native error: {0}")]
Native(i32),
/// An error that occurred while accessing or allocating memory
#[error("memory error: {0}")]
Memory(std::borrow::Cow<'static, str>),
/// An error that occurred while parsing a data source
#[error("parse error: {0}")]
Parse(String),
/// An error that occurred while working with a file path.
#[error("path error: {0}")]
Path(std::path::PathBuf),
/// Generally, these errors correspond to bugs in this library.
#[error("BUG: Please report this bug with a backtrace to https://github.com/gwihlidal/meshopt-rs\n{0}")]
Bug(String),
/// An error occurred while reading/writing a configuration
#[error("config error: {0}")]
Config(String),
/// An unexpected I/O error occurred.
#[error(transparent)]
Io(#[from] std::io::Error),
// An error occurred while parsing a number in a free-form query.
//Number,
}
impl Error {
#[inline]
pub(crate) fn memory(msg: &'static str) -> Self {
Self::Memory(std::borrow::Cow::Borrowed(msg))
}
#[inline]
pub(crate) fn memory_dynamic(msg: String) -> Self {
Self::Memory(std::borrow::Cow::Owned(msg))
}
}
#[inline]
pub(crate) fn error_or<T>(code: i32, ok: T) -> Result<T> {
if code == 0 {
Ok(ok)
} else {
Err(Error::Native(code))
}
}