diff options
author | Alan Somers <asomers@gmail.com> | 2021-07-13 08:19:05 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2021-07-13 08:19:05 -0600 |
commit | 50391ef8624e47bd9b58f1240ec9a2ae6fda705a (patch) | |
tree | 241cbda1c6e3394e47c15da50e27868ecf819d28 | |
parent | e493f83fa6aed69066474e98cf51eb1771d8fcf3 (diff) | |
download | nix-50391ef8624e47bd9b58f1240ec9a2ae6fda705a.zip |
Use immutable receivers for FdSet::{highest, contains, fds}
There was never any good reason to use mutable receives in the first
place. Nix originally did so because libc defined FD_ISSET as taking a
mutable receiver, which it did based on an inaccurate Linux man page.
But that's fixed now.
https://github.com/rust-lang/libc/pull/1725
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/sys/select.rs | 10 |
3 files changed, 10 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 21cb4b85..9e8803fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - ReleaseDate ### Added ### Changed + +- `FdSet::{contains, highest, fds}` no longer require a mutable reference. + (#[1464](https://github.com/nix-rust/nix/pull/1464)) + ### Fixed ### Removed @@ -25,7 +25,7 @@ targets = [ ] [dependencies] -libc = { version = "0.2.98", features = [ "extra_traits" ] } +libc = { git = "https://github.com/rust-lang/libc", rev = "9c1489fa8", features = [ "extra_traits" ] } bitflags = "1.1" cfg-if = "1.0" diff --git a/src/sys/select.rs b/src/sys/select.rs index 5eb64234..a8035f79 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -32,8 +32,8 @@ impl FdSet { unsafe { libc::FD_CLR(fd, &mut self.0) }; } - pub fn contains(&mut self, fd: RawFd) -> bool { - unsafe { libc::FD_ISSET(fd, &mut self.0) } + pub fn contains(&self, fd: RawFd) -> bool { + unsafe { libc::FD_ISSET(fd, &self.0) } } pub fn clear(&mut self) { @@ -57,7 +57,7 @@ impl FdSet { /// ``` /// /// [`select`]: fn.select.html - pub fn highest(&mut self) -> Option<RawFd> { + pub fn highest(&self) -> Option<RawFd> { self.fds(None).next_back() } @@ -79,7 +79,7 @@ impl FdSet { /// assert_eq!(fds, vec![4, 9]); /// ``` #[inline] - pub fn fds(&mut self, highest: Option<RawFd>) -> Fds { + pub fn fds(&self, highest: Option<RawFd>) -> Fds { Fds { set: self, range: 0..highest.map(|h| h as usize + 1).unwrap_or(FD_SETSIZE), @@ -96,7 +96,7 @@ impl Default for FdSet { /// Iterator over `FdSet`. #[derive(Debug)] pub struct Fds<'a> { - set: &'a mut FdSet, + set: &'a FdSet, range: Range<usize>, } |