Mercurial > crates > nonstick
comparison libpam-sys/libpam-sys-helpers/src/constants.rs @ 138:999bf07efbcb
Get rid of num_enum dependency in `libpam-sys-helpers`.
Build times now fast!
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Thu, 03 Jul 2025 20:55:40 -0400 |
| parents | 88627c057709 |
| children |
comparison
equal
deleted
inserted
replaced
| 137:88627c057709 | 138:999bf07efbcb |
|---|---|
| 2 //! | 2 //! |
| 3 //! These constants are tested on a per-platform basis by `libpam-sys-test`'s | 3 //! These constants are tested on a per-platform basis by `libpam-sys-test`'s |
| 4 //! `test_constants.rs`. | 4 //! `test_constants.rs`. |
| 5 | 5 |
| 6 #![allow(non_camel_case_types)] | 6 #![allow(non_camel_case_types)] |
| 7 #![allow(unused_imports)] | |
| 8 use num_enum::{IntoPrimitive, TryFromPrimitive}; | |
| 9 | 7 |
| 10 /// Macro to make defining a bunch of constants way easier. | 8 /// Macro to make defining a bunch of constants way easier. |
| 11 macro_rules! define { | 9 macro_rules! define { |
| 12 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { | 10 ($(#[$attr:meta])* $($name:ident = $value:expr);+$(;)?) => { |
| 13 define!( | 11 define!( |
| 74 | 72 |
| 75 #[cfg(pam_impl = "LinuxPam")] | 73 #[cfg(pam_impl = "LinuxPam")] |
| 76 pub use linux_pam::*; | 74 pub use linux_pam::*; |
| 77 #[cfg(pam_impl = "LinuxPam")] | 75 #[cfg(pam_impl = "LinuxPam")] |
| 78 mod linux_pam { | 76 mod linux_pam { |
| 79 use super::{IntoPrimitive, TryFromPrimitive}; | |
| 80 c_enum!( | 77 c_enum!( |
| 81 /// An error return code. | 78 /// An error return code. |
| 82 PAM_OPEN_ERR = 1, | 79 PAM_OPEN_ERR = 1, |
| 83 PAM_SYMBOL_ERR, | 80 PAM_SYMBOL_ERR, |
| 84 PAM_SERVICE_ERR, | 81 PAM_SERVICE_ERR, |
| 147 PAM_BINARY_PROMPT = 7; | 144 PAM_BINARY_PROMPT = 7; |
| 148 ); | 145 ); |
| 149 | 146 |
| 150 pub const PAM_MODUTIL_NGROUPS: i32 = 64; | 147 pub const PAM_MODUTIL_NGROUPS: i32 = 64; |
| 151 | 148 |
| 152 #[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] | 149 #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 153 #[repr(i32)] | 150 #[repr(i32)] |
| 154 pub enum pam_modutil_redirect_fd { | 151 pub enum pam_modutil_redirect_fd { |
| 155 PAM_MODUTIL_IGNORE_FD, | 152 PAM_MODUTIL_IGNORE_FD, |
| 156 PAM_MODUTIL_PIPE_FD, | 153 PAM_MODUTIL_PIPE_FD, |
| 157 PAM_MODUTIL_NULL_FD, | 154 PAM_MODUTIL_NULL_FD, |
| 155 } | |
| 156 | |
| 157 impl From<pam_modutil_redirect_fd> for i32 { | |
| 158 fn from(value: pam_modutil_redirect_fd) -> Self { | |
| 159 value as Self | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 impl TryFrom<i32> for pam_modutil_redirect_fd { | |
| 164 type Error = i32; | |
| 165 fn try_from(value: i32) -> Result<Self, Self::Error> { | |
| 166 match value { | |
| 167 0..=2 => Ok(unsafe { *(&value as *const i32).cast() }), | |
| 168 other => Err(other), | |
| 169 } | |
| 170 } | |
| 158 } | 171 } |
| 159 | 172 |
| 160 pub use pam_modutil_redirect_fd::*; | 173 pub use pam_modutil_redirect_fd::*; |
| 161 } | 174 } |
| 162 | 175 |
