Mercurial > crates > nonstick
diff 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 |
line wrap: on
line diff
--- a/libpam-sys/libpam-sys-helpers/src/constants.rs Thu Jul 03 17:33:13 2025 -0400 +++ b/libpam-sys/libpam-sys-helpers/src/constants.rs Thu Jul 03 20:55:40 2025 -0400 @@ -4,8 +4,6 @@ //! `test_constants.rs`. #![allow(non_camel_case_types)] -#![allow(unused_imports)] -use num_enum::{IntoPrimitive, TryFromPrimitive}; /// Macro to make defining a bunch of constants way easier. macro_rules! define { @@ -76,7 +74,6 @@ pub use linux_pam::*; #[cfg(pam_impl = "LinuxPam")] mod linux_pam { - use super::{IntoPrimitive, TryFromPrimitive}; c_enum!( /// An error return code. PAM_OPEN_ERR = 1, @@ -149,7 +146,7 @@ pub const PAM_MODUTIL_NGROUPS: i32 = 64; - #[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] + #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(i32)] pub enum pam_modutil_redirect_fd { PAM_MODUTIL_IGNORE_FD, @@ -157,6 +154,22 @@ PAM_MODUTIL_NULL_FD, } + impl From<pam_modutil_redirect_fd> for i32 { + fn from(value: pam_modutil_redirect_fd) -> Self { + value as Self + } + } + + impl TryFrom<i32> for pam_modutil_redirect_fd { + type Error = i32; + fn try_from(value: i32) -> Result<Self, Self::Error> { + match value { + 0..=2 => Ok(unsafe { *(&value as *const i32).cast() }), + other => Err(other), + } + } + } + pub use pam_modutil_redirect_fd::*; }