From 08e784960af955a032c5995da7880b36cbe1e4b6 Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Sat, 16 Mar 2024 16:39:34 +0800 Subject: [PATCH] feat: make SigAction repr(transparent)&From&Into (#2326) * feat: make SigAction repr(transparent)&From&Into * style: fix clippy --- changelog/2326.added.md | 1 + src/sys/signal.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 changelog/2326.added.md diff --git a/changelog/2326.added.md b/changelog/2326.added.md new file mode 100644 index 0000000000..bcc29cb3db --- /dev/null +++ b/changelog/2326.added.md @@ -0,0 +1 @@ +make SigAction repr(transparent) & can be converted to/from the libc raw type diff --git a/src/sys/signal.rs b/src/sys/signal.rs index c9b593d0db..2a9c0027a9 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -753,11 +753,25 @@ pub enum SigHandler { } /// Action to take on receipt of a signal. Corresponds to `sigaction`. +#[repr(transparent)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct SigAction { sigaction: libc::sigaction } +impl From for SigAction { + fn from(value: libc::sigaction) -> Self { + Self { + sigaction: value + } + } +} +impl From for libc::sigaction { + fn from(value: SigAction) -> libc::sigaction { + value.sigaction + } +} + impl SigAction { /// Creates a new action. ///