diff src/libpam/question.rs @ 180:a1bb1d013567

Remove `syn` from the dependency tree by implementing our own num_enum.
author Paul Fisher <paul@pfish.zone>
date Wed, 30 Jul 2025 18:22:16 -0400
parents dba9c1f40883
children
line wrap: on
line diff
--- a/src/libpam/question.rs	Wed Jul 30 18:07:51 2025 -0400
+++ b/src/libpam/question.rs	Wed Jul 30 18:22:16 2025 -0400
@@ -6,32 +6,31 @@
 use crate::ErrorCode;
 use crate::Result;
 use libpam_sys_helpers;
-use num_enum::{IntoPrimitive, TryFromPrimitive};
 use std::ffi::{c_int, c_void, CStr, OsStr};
 use std::os::unix::ffi::OsStrExt;
 use std::ptr::NonNull;
 
-/// The C enum values for messages shown to the user.
-#[derive(Debug, PartialEq, TryFromPrimitive, IntoPrimitive)]
-#[repr(i32)]
-enum Style {
-    /// Requests information from the user; will be masked when typing.
-    PromptEchoOff = libpam_sys::PAM_PROMPT_ECHO_OFF,
-    /// Requests information from the user; will not be masked.
-    PromptEchoOn = libpam_sys::PAM_PROMPT_ECHO_ON,
-    /// An error message.
-    ErrorMsg = libpam_sys::PAM_ERROR_MSG,
-    /// An informational message.
-    TextInfo = libpam_sys::PAM_TEXT_INFO,
-    /// Yes/No/Maybe conditionals. A Linux-PAM extension.
-    #[cfg(feature = "linux-pam-ext")]
-    RadioType = libpam_sys::PAM_RADIO_TYPE,
-    /// For server–client non-human interaction.
-    ///
-    /// NOT part of the X/Open PAM specification.
-    /// A Linux-PAM extension.
-    #[cfg(feature = "linux-pam-ext")]
-    BinaryPrompt = libpam_sys::PAM_BINARY_PROMPT,
+memory::num_enum! {
+    /// The C enum values for messages shown to the user.
+    enum Style(i32) {
+        /// Requests information from the user; will be masked when typing.
+        PromptEchoOff = libpam_sys::PAM_PROMPT_ECHO_OFF,
+        /// Requests information from the user; will not be masked.
+        PromptEchoOn = libpam_sys::PAM_PROMPT_ECHO_ON,
+        /// An error message.
+        ErrorMsg = libpam_sys::PAM_ERROR_MSG,
+        /// An informational message.
+        TextInfo = libpam_sys::PAM_TEXT_INFO,
+        /// Yes/No/Maybe conditionals. A Linux-PAM extension.
+        #[cfg(feature = "linux-pam-ext")]
+        RadioType = libpam_sys::PAM_RADIO_TYPE,
+        /// For server–client non-human interaction.
+        ///
+        /// NOT part of the X/Open PAM specification.
+        /// A Linux-PAM extension.
+        #[cfg(feature = "linux-pam-ext")]
+        BinaryPrompt = libpam_sys::PAM_BINARY_PROMPT,
+    }
 }
 
 /// A question sent by PAM or a module to an application.