Skip to content

Commit 6906a61

Browse files
Sigset conveniance (#1959)
* 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`
1 parent ae9b092 commit 6906a61

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1111

1212
- Fixed the function signature of `recvmmsg`, potentially causing UB
1313
([#2119](https://github.com/nix-rust/nix/issues/2119))
14+
### Added
15+
16+
- Added `impl From<Signal> for SigSet`.
17+
([#1959](https://github.com/nix-rust/nix/pull/1959))
18+
- Added `impl std::ops::BitOr for SigSet`.
19+
([#1959](https://github.com/nix-rust/nix/pull/1959))
20+
- Added `impl std::ops::BitOr for Signal`.
21+
([#1959](https://github.com/nix-rust/nix/pull/1959))
22+
- Added `impl std::ops::BitOr<Signal> for SigSet`
23+
([#1959](https://github.com/nix-rust/nix/pull/1959))
1424

1525
- Fix `SignalFd::set_mask`. In 0.27.0 it would actually close the file
1626
descriptor.

src/sys/signal.rs

+37
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use cfg_if::cfg_if;
99
use std::fmt;
1010
use std::hash::{Hash, Hasher};
1111
use std::mem;
12+
use std::ops::BitOr;
1213
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
1314
use std::os::unix::io::RawFd;
1415
use std::ptr;
@@ -604,6 +605,42 @@ impl SigSet {
604605
}
605606
}
606607

608+
impl From<Signal> for SigSet {
609+
fn from(signal: Signal) -> SigSet {
610+
let mut sigset = SigSet::empty();
611+
sigset.add(signal);
612+
sigset
613+
}
614+
}
615+
616+
impl BitOr for Signal {
617+
type Output = SigSet;
618+
619+
fn bitor(self, rhs: Self) -> Self::Output {
620+
let mut sigset = SigSet::empty();
621+
sigset.add(self);
622+
sigset.add(rhs);
623+
sigset
624+
}
625+
}
626+
627+
impl BitOr<Signal> for SigSet {
628+
type Output = SigSet;
629+
630+
fn bitor(mut self, rhs: Signal) -> Self::Output {
631+
self.add(rhs);
632+
self
633+
}
634+
}
635+
636+
impl BitOr for SigSet {
637+
type Output = Self;
638+
639+
fn bitor(self, rhs: Self) -> Self::Output {
640+
self.iter().chain(rhs.iter()).collect()
641+
}
642+
}
643+
607644
impl AsRef<libc::sigset_t> for SigSet {
608645
fn as_ref(&self) -> &libc::sigset_t {
609646
&self.sigset

0 commit comments

Comments
 (0)