endpoint_sec_sys/
result_wrapping.rs1#[cfg(doc)]
6use super::*;
7#[cfg(feature = "macos_13_0_0")]
8use crate::es_mute_inverted_return_t;
9
10macro_rules! result_types {
12 (
20 $(#[$enum_doc:meta])+
21 enum $rust_name:ident =
22 $c_name:ident with
23 $success_c_variant:ident;
24 $($(#[$variant_meta: meta])? $rust_variant:ident is $c_variant:ident),+ $(,)?
25 ) => {
26 $(#[$enum_doc] )+
28 #[doc = ""]
29 #[doc = "Usually constructed using "]
31 #[doc = ::std::concat!("[`", ::std::stringify!($c_name), "::ok()`].")]
32 #[derive(::std::fmt::Debug, ::std::clone::Clone, ::std::marker::Copy, ::std::cmp::PartialEq, ::std::cmp::Eq, ::std::hash::Hash)]
33 pub enum $rust_name {
34 $(
36 #[doc = ::std::concat!(
37 "See [`", ::std::stringify!($c_variant), "`]",
38 "[", ::std::stringify!($c_name), "::", ::std::stringify!($c_variant), "]"
39 )]
40 $(#[$variant_meta])?
41 $rust_variant,
42 )+
43 Unknown($crate::$c_name),
45 ApiUnavailable,
49 }
50
51 impl ::std::fmt::Display for $crate::$rust_name {
54 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
55 match self {
56 $( $(#[$variant_meta])? Self::$rust_variant => ::std::write!(f, ::std::stringify!($c_variant)), )+
57 Self::Unknown(err) => ::std::write!(f, ::std::concat!(::std::stringify!($c_name), "({:#X})"), err.0),
58 Self::ApiUnavailable => ::std::write!(f, "API is unavailable in this version of macOS"),
59 }
60 }
61 }
62
63 impl ::std::error::Error for $crate::$rust_name {}
64
65 impl $crate::$c_name {
67 #[doc = "Converts an instance of [`"]
68 #[doc = ::std::stringify!($c_name)]
69 #[doc = "`] to a [`Result`]`<(), `[`"]
70 #[doc = ::std::stringify!($rust_name)]
71 #[doc = "`]`>`"]
72 pub fn ok(self) -> ::std::result::Result<(), $crate::$rust_name> {
73 let err = match self {
74 Self::$success_c_variant => return ::std::result::Result::Ok(()),
75 $( $(#[$variant_meta])? Self::$c_variant => $crate::$rust_name::$rust_variant, )+
76 err => $crate::$rust_name::Unknown(err),
77 };
78
79 ::std::result::Result::Err(err)
80 }
81 }
82 };
83}
84
85result_types!(
86 #[doc(alias = "es_return_t")]
88 enum ReturnError = es_return_t with ES_RETURN_SUCCESS;
89 Error is ES_RETURN_ERROR,
90);
91
92result_types!(
93 #[doc(alias = "es_respond_result_t")]
95 enum RespondError = es_respond_result_t with ES_RESPOND_RESULT_SUCCESS;
96 InvalidArgument is ES_RESPOND_RESULT_ERR_INVALID_ARGUMENT,
97 Internal is ES_RESPOND_RESULT_ERR_INTERNAL,
98 MessageNotFound is ES_RESPOND_RESULT_NOT_FOUND,
99 DuplicateResponse is ES_RESPOND_RESULT_ERR_DUPLICATE_RESPONSE,
100 EventType is ES_RESPOND_RESULT_ERR_EVENT_TYPE,
101);
102
103result_types!(
104 #[doc(alias = "es_clear_cache_result_t")]
106 enum ClearCacheError = es_clear_cache_result_t with ES_CLEAR_CACHE_RESULT_SUCCESS;
107 Internal is ES_CLEAR_CACHE_RESULT_ERR_INTERNAL,
108 Throttle is ES_CLEAR_CACHE_RESULT_ERR_THROTTLE,
109);
110
111result_types!(
112 #[doc(alias = "es_new_client_result_t")]
114 enum NewClientError = es_new_client_result_t with ES_NEW_CLIENT_RESULT_SUCCESS;
115 InvalidArgument is ES_NEW_CLIENT_RESULT_ERR_INVALID_ARGUMENT,
116 Internal is ES_NEW_CLIENT_RESULT_ERR_INTERNAL,
117 NotEntitled is ES_NEW_CLIENT_RESULT_ERR_NOT_ENTITLED,
118 NotPermitted is ES_NEW_CLIENT_RESULT_ERR_NOT_PERMITTED,
119 NotPrivileged is ES_NEW_CLIENT_RESULT_ERR_NOT_PRIVILEGED,
120 #[cfg(feature = "macos_10_15_1")]
121 TooManyClients is ES_NEW_CLIENT_RESULT_ERR_TOO_MANY_CLIENTS,
122);
123
124#[cfg(feature = "macos_13_0_0")]
125result_types!(
126 #[doc(alias = "es_openssh_login_result_type_t")]
128 enum OpensshLoginError = es_openssh_login_result_type_t with ES_OPENSSH_AUTH_SUCCESS;
129 LoginExceedMaxTries is ES_OPENSSH_LOGIN_EXCEED_MAXTRIES,
130 LoginRootDenied is ES_OPENSSH_LOGIN_ROOT_DENIED,
131 AuthNone is ES_OPENSSH_AUTH_FAIL_NONE,
132 AuthPassword is ES_OPENSSH_AUTH_FAIL_PASSWD,
133 AuthKbdint is ES_OPENSSH_AUTH_FAIL_KBDINT,
134 AuthPubkey is ES_OPENSSH_AUTH_FAIL_PUBKEY,
135 AuthHostBased is ES_OPENSSH_AUTH_FAIL_HOSTBASED,
136 AuthGssapi is ES_OPENSSH_AUTH_FAIL_GSSAPI,
137 InvalidUser is ES_OPENSSH_INVALID_USER,
138);
139
140#[doc(alias = "es_mute_inverted_return_t")]
147#[cfg(feature = "macos_13_0_0")]
148#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
149pub enum MuteInvertedType {
150 Normal,
154 Inverted,
158}
159
160#[doc(alias = "es_mute_inverted_return_t")]
164#[cfg(feature = "macos_13_0_0")]
165#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
166pub enum MuteTypeError {
167 Error,
169 Unknown(es_mute_inverted_return_t),
171 ApiUnavailable,
175}
176
177#[cfg(feature = "macos_13_0_0")]
180impl ::std::fmt::Display for MuteTypeError {
181 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
182 match self {
183 Self::Error => ::std::write!(f, "ES_MUTE_INVERTED_ERROR"),
184 Self::Unknown(err) => ::std::write!(f, "es_mute_inverted_return_t({:#X})", err.0),
185 Self::ApiUnavailable => ::std::write!(f, "API is unavailable in this version of macOS"),
186 }
187 }
188}
189
190#[cfg(feature = "macos_13_0_0")]
191impl ::std::error::Error for MuteTypeError {}
192
193#[cfg(feature = "macos_13_0_0")]
194impl es_mute_inverted_return_t {
195 pub fn ok(self) -> Result<MuteInvertedType, MuteTypeError> {
198 match self {
199 Self::ES_MUTE_INVERTED => Ok(MuteInvertedType::Inverted),
200 Self::ES_MUTE_NOT_INVERTED => Ok(MuteInvertedType::Normal),
201 Self::ES_MUTE_INVERTED_ERROR => Err(MuteTypeError::Error),
202 err => Err(MuteTypeError::Unknown(err)),
203 }
204 }
205}