From 567437750303507ef54573eb1f72d5d285bed414 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Mon, 16 Dec 2024 16:30:51 -0800 Subject: [PATCH] Add from_owned_fd constructor to EventFd (#2563) * add from_owned_fd to EventFd * update changelog * fix safety section --- changelog/2563.added.md | 1 + src/sys/eventfd.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelog/2563.added.md diff --git a/changelog/2563.added.md b/changelog/2563.added.md new file mode 100644 index 0000000000..2b61f37bec --- /dev/null +++ b/changelog/2563.added.md @@ -0,0 +1 @@ +Added `from_owned_fd` constructor to `EventFd` diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index b7860e683f..382a72e75c 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -58,6 +58,15 @@ impl EventFd { Self::from_value_and_flags(init_val, EfdFlags::empty()) } + /// Constructs an `EventFd` wrapping an existing `OwnedFd`. + /// + /// # Safety + /// + /// `OwnedFd` is a valid eventfd. + pub unsafe fn from_owned_fd(fd: OwnedFd) -> Self { + Self(fd) + } + /// Enqueues `value` triggers, i.e., adds the integer value supplied in `value` /// to the counter. /// @@ -106,4 +115,4 @@ impl From for OwnedFd { fn from(value: EventFd) -> Self { value.0 } -} \ No newline at end of file +}