Skip to content

Commit e6e25ec

Browse files
committed
Prefer to pass Inotify by value instead of by reference
It's small and `Copy`, so pass by value is more efficient. This is technically a breaking change, but most code should compile without changes.
1 parent 729e782 commit e6e25ec

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4949
- `sys::socket::sockaddr_storage_to_addr` is no longer `unsafe`. So is
5050
`offset_of!`.
5151
(#[1244](https://github.com/nix-rust/nix/pull/1244))
52+
- Several `Inotify` methods now take `self` by value instead of by reference
53+
(#[1244](https://github.com/nix-rust/nix/pull/1244))
5254

5355
### Fixed
5456

src/sys/inotify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Inotify {
131131
/// Returns a watch descriptor. This is not a File Descriptor!
132132
///
133133
/// For more information see, [inotify_add_watch(2)](http://man7.org/linux/man-pages/man2/inotify_add_watch.2.html).
134-
pub fn add_watch<P: ?Sized + NixPath>(&self,
134+
pub fn add_watch<P: ?Sized + NixPath>(self,
135135
path: &P,
136136
mask: AddWatchFlags)
137137
-> Result<WatchDescriptor>
@@ -152,14 +152,14 @@ impl Inotify {
152152
///
153153
/// For more information see, [inotify_rm_watch(2)](http://man7.org/linux/man-pages/man2/inotify_rm_watch.2.html).
154154
#[cfg(target_os = "linux")]
155-
pub fn rm_watch(&self, wd: WatchDescriptor) -> Result<()> {
155+
pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()> {
156156
let res = unsafe { libc::inotify_rm_watch(self.fd, wd.wd) };
157157

158158
Errno::result(res).map(drop)
159159
}
160160

161161
#[cfg(target_os = "android")]
162-
pub fn rm_watch(&self, wd: WatchDescriptor) -> Result<()> {
162+
pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()> {
163163
let res = unsafe { libc::inotify_rm_watch(self.fd, wd.wd as u32) };
164164

165165
Errno::result(res).map(drop)
@@ -171,7 +171,7 @@ impl Inotify {
171171
///
172172
/// Returns as many events as available. If the call was non blocking and no
173173
/// events could be read then the EAGAIN error is returned.
174-
pub fn read_events(&self) -> Result<Vec<InotifyEvent>> {
174+
pub fn read_events(self) -> Result<Vec<InotifyEvent>> {
175175
let header_size = size_of::<libc::inotify_event>();
176176
const BUFSIZ: usize = 4096;
177177
let mut buffer = [0u8; BUFSIZ];

0 commit comments

Comments
 (0)