Skip to main content

maplibre_native_ffi/
status.rs

1// Generated from C headers by tools/bindgen. Do not edit.
2/// The result of a call or of asynchronous work.
3///
4/// See `mln_status` in the
5/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum Status {
8    Ok,
9    /// An argument is invalid, such as malformed JSON or a value out of range.
10    InvalidArgument,
11    /// The call doesn't fit the current state, such as removing a source that a
12    /// layer still uses.
13    InvalidState,
14    /// The call came from a thread that can't make it.
15    WrongThread,
16    /// The platform, the build, or the render target lacks the feature.
17    Unsupported,
18    /// The library or the platform hit an error, such as a failed graphics
19    /// driver call.
20    NativeError,
21    /// The work stopped before it finished, such as when its handle was
22    /// released.
23    Cancelled,
24    /// Another call is still using the same object.
25    Busy,
26    /// The render target can't be drawn to anymore.
27    TargetLost,
28    /// Nothing has the given ID.
29    NotFound,
30    /// Something already has the given ID.
31    AlreadyExists,
32    Unknown(i32),
33}
34impl Status {
35    pub fn from_raw(raw: i32) -> Self {
36        match raw {
37            0 => Self::Ok,
38            -1 => Self::InvalidArgument,
39            -2 => Self::InvalidState,
40            -3 => Self::WrongThread,
41            -4 => Self::Unsupported,
42            -5 => Self::NativeError,
43            -6 => Self::Cancelled,
44            -7 => Self::Busy,
45            -8 => Self::TargetLost,
46            -10 => Self::NotFound,
47            -11 => Self::AlreadyExists,
48            value => Self::Unknown(value),
49        }
50    }
51    pub fn as_raw(self) -> i32 {
52        match self {
53            Self::Ok => 0,
54            Self::InvalidArgument => -1,
55            Self::InvalidState => -2,
56            Self::WrongThread => -3,
57            Self::Unsupported => -4,
58            Self::NativeError => -5,
59            Self::Cancelled => -6,
60            Self::Busy => -7,
61            Self::TargetLost => -8,
62            Self::NotFound => -10,
63            Self::AlreadyExists => -11,
64            Self::Unknown(value) => value,
65        }
66    }
67}
68impl Default for Status {
69    fn default() -> Self {
70        Self::from_raw(0)
71    }
72}
73impl std::fmt::Display for Status {
74    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75        match self {
76            Self::Ok => f.write_str("OK"),
77            Self::InvalidArgument => f.write_str("INVALID_ARGUMENT"),
78            Self::InvalidState => f.write_str("INVALID_STATE"),
79            Self::WrongThread => f.write_str("WRONG_THREAD"),
80            Self::Unsupported => f.write_str("UNSUPPORTED"),
81            Self::NativeError => f.write_str("NATIVE_ERROR"),
82            Self::Cancelled => f.write_str("CANCELLED"),
83            Self::Busy => f.write_str("BUSY"),
84            Self::TargetLost => f.write_str("TARGET_LOST"),
85            Self::NotFound => f.write_str("NOT_FOUND"),
86            Self::AlreadyExists => f.write_str("ALREADY_EXISTS"),
87            Self::Unknown(value) => write!(f, "UNKNOWN({value})"),
88        }
89    }
90}