Skip to content

Commit

Permalink
Sigset conveniance (#1959)
Browse files Browse the repository at this point in the history
* feat: `impl From<Signal> for SigSet`

* feat: `impl std::ops::BitOr for SigSet`

* feat: `impl std::ops::BitOr for Signal`

* feat: `impl std::ops::BitOr<Signal> for SigSet`
  • Loading branch information
JonathanWoollett-Light committed Oct 5, 2023
1 parent ae9b092 commit 6906a61
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- Fixed the function signature of `recvmmsg`, potentially causing UB
([#2119](https://github.com/nix-rust/nix/issues/2119))
### Added

- Added `impl From<Signal> for SigSet`.
([#1959](https://github.com/nix-rust/nix/pull/1959))
- Added `impl std::ops::BitOr for SigSet`.
([#1959](https://github.com/nix-rust/nix/pull/1959))
- Added `impl std::ops::BitOr for Signal`.
([#1959](https://github.com/nix-rust/nix/pull/1959))
- Added `impl std::ops::BitOr<Signal> for SigSet`
([#1959](https://github.com/nix-rust/nix/pull/1959))

- Fix `SignalFd::set_mask`. In 0.27.0 it would actually close the file
descriptor.
Expand Down
37 changes: 37 additions & 0 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cfg_if::cfg_if;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::BitOr;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
use std::os::unix::io::RawFd;
use std::ptr;
Expand Down Expand Up @@ -604,6 +605,42 @@ impl SigSet {
}
}

impl From<Signal> for SigSet {
fn from(signal: Signal) -> SigSet {
let mut sigset = SigSet::empty();
sigset.add(signal);
sigset
}
}

impl BitOr for Signal {
type Output = SigSet;

fn bitor(self, rhs: Self) -> Self::Output {
let mut sigset = SigSet::empty();
sigset.add(self);
sigset.add(rhs);
sigset
}
}

impl BitOr<Signal> for SigSet {
type Output = SigSet;

fn bitor(mut self, rhs: Signal) -> Self::Output {
self.add(rhs);
self
}
}

impl BitOr for SigSet {
type Output = Self;

fn bitor(self, rhs: Self) -> Self::Output {
self.iter().chain(rhs.iter()).collect()
}
}

impl AsRef<libc::sigset_t> for SigSet {
fn as_ref(&self) -> &libc::sigset_t {
&self.sigset
Expand Down

0 comments on commit 6906a61

Please sign in to comment.