Skip to content

Commit fb7a0d2

Browse files
Remove Copy from PollFd
PollFd implementing Copy makes it easy to accidentally refer to the wrong object after putting one into an array. This fixes nix-rust#2630
1 parent b561476 commit fb7a0d2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/poll.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::Result;
1414
/// After a call to `poll` or `ppoll`, the events that occurred can be
1515
/// retrieved by calling [`revents()`](#method.revents) on the `PollFd`.
1616
#[repr(transparent)]
17-
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
17+
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1818
pub struct PollFd<'fd> {
1919
pollfd: libc::pollfd,
2020
_fd: std::marker::PhantomData<BorrowedFd<'fd>>,
@@ -61,7 +61,7 @@ impl<'fd> PollFd<'fd> {
6161

6262
/// Returns the events that occurred in the last call to `poll` or `ppoll`. Will only return
6363
/// `None` if the kernel provides status flags that Nix does not know about.
64-
pub fn revents(self) -> Option<PollFlags> {
64+
pub fn revents(&self) -> Option<PollFlags> {
6565
PollFlags::from_bits(self.pollfd.revents)
6666
}
6767

@@ -71,7 +71,7 @@ impl<'fd> PollFd<'fd> {
7171
/// Equivalent to `x.revents()? != PollFlags::empty()`.
7272
///
7373
/// This is marginally more efficient than [`PollFd::all`].
74-
pub fn any(self) -> Option<bool> {
74+
pub fn any(&self) -> Option<bool> {
7575
Some(self.revents()? != PollFlags::empty())
7676
}
7777

@@ -81,12 +81,12 @@ impl<'fd> PollFd<'fd> {
8181
/// Equivalent to `x.revents()? & x.events() == x.events()`.
8282
///
8383
/// This is marginally less efficient than [`PollFd::any`].
84-
pub fn all(self) -> Option<bool> {
84+
pub fn all(&self) -> Option<bool> {
8585
Some(self.revents()? & self.events() == self.events())
8686
}
8787

8888
/// The events of interest for this `PollFd`.
89-
pub fn events(self) -> PollFlags {
89+
pub fn events(&self) -> PollFlags {
9090
PollFlags::from_bits(self.pollfd.events).unwrap()
9191
}
9292

0 commit comments

Comments
 (0)