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 +}