1pub type Result<T> = std::result::Result<T, Error>;
3
4#[derive(Debug, thiserror::Error)]
6#[non_exhaustive]
7pub enum Error {
8 #[error("native error: {0}")]
10 Native(i32),
11
12 #[error("memory error: {0}")]
14 Memory(std::borrow::Cow<'static, str>),
15
16 #[error("parse error: {0}")]
18 Parse(String),
19
20 #[error("path error: {0}")]
22 Path(std::path::PathBuf),
23
24 #[error("BUG: Please report this bug with a backtrace to https://github.com/gwihlidal/meshopt-rs\n{0}")]
26 Bug(String),
27
28 #[error("config error: {0}")]
30 Config(String),
31
32 #[error(transparent)]
34 Io(#[from] std::io::Error),
35 }
38
39impl Error {
40 #[inline]
41 pub(crate) fn memory(msg: &'static str) -> Self {
42 Self::Memory(std::borrow::Cow::Borrowed(msg))
43 }
44
45 #[inline]
46 pub(crate) fn memory_dynamic(msg: String) -> Self {
47 Self::Memory(std::borrow::Cow::Owned(msg))
48 }
49}
50
51#[inline]
52pub(crate) fn error_or<T>(code: i32, ok: T) -> Result<T> {
53 if code == 0 {
54 Ok(ok)
55 } else {
56 Err(Error::Native(code))
57 }
58}