Repository: hannobraun/inotify-rs (language: rust)

Issue:
Update bitflags dependency
[Bitflags 1.0](https://crates.io/crates/bitflags) has been released, now using associated constants. This looks like an improvement, but is a breaking change, so I think we should upgrade sooner rather than later.


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index ffdcb44..3078e00 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,7 +22,7 @@ categories = ["api-bindings", "filesystem"]
 travis-ci = { repository = "hannobraun/inotify-rs" }
 
 [dependencies]
-bitflags    = "0.9"
+bitflags    = "1"
 inotify-sys = "0.1.1"
 libc        = "0.2"
 
diff --git a/examples/watch.rs b/examples/watch.rs
index 016038c..3aa7a10 100644
--- a/examples/watch.rs
+++ b/examples/watch.rs
@@ -4,9 +4,9 @@ extern crate inotify;
 use std::env;
 
 use inotify::{
-    event_mask,
-    watch_mask,
+    EventMask,
     Inotify,
+    WatchMask,
 };
 
 
@@ -20,7 +20,7 @@ fn main() {
     inotify
         .add_watch(
             current_dir,
-            watch_mask::MODIFY | watch_mask::CREATE | watch_mask::DELETE,
+            WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE,
         )
         .expect("Failed to add inotify watch");
 
@@ -33,20 +33,20 @@ fn main() {
             .expect("Failed to read inotify events");
 
         for event in events {
-            if event.mask.contains(event_mask::CREATE) {
-                if event.mask.contains(event_mask::ISDIR) {
+            if event.mask.contains(EventMask::CREATE) {
+                if event.mask.contains(EventMask::ISDIR) {
                     println!("Directory created: {:?}", event.name);
                 } else {
                     println!("File created: {:?}", event.name);
                 }
-            } else if event.mask.contains(event_mask::DELETE) {
-                if event.mask.contains(event_mask::ISDIR) {
+            } else if event.mask.contains(EventMask::DELETE) {
+                if event.mask.contains(EventMask::ISDIR) {
                     println!("Directory deleted: {:?}", event.name);
                 } else {
                     println!("File deleted: {:?}", event.name);
                 }
-            } else if event.mask.contains(event_mask::MODIFY) {
-                if event.mask.contains(event_mask::ISDIR) {
+            } else if event.mask.contains(EventMask::MODIFY) {
+                if event.mask.contains(EventMask::ISDIR) {
                     println!("Directory modified: {:?}", event.name);
                 } else {
                     println!("File modified: {:?}", event.name);
diff --git a/src/lib.rs b/src/lib.rs
index 3f3bb59..1c9fc77 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -79,7 +79,7 @@ use libc::{
 /// ```
 /// use inotify::{
 ///     Inotify,
-///     watch_mask,
+///     WatchMask,
 /// };
 ///
 /// let mut inotify = Inotify::init()
@@ -94,7 +94,7 @@ use libc::{
 /// inotify
 ///     .add_watch(
 ///         "/tmp/inotify-rs-test-file",
-///         watch_mask::MODIFY | watch_mask::CLOSE,
+///         WatchMask::MODIFY | WatchMask::CLOSE,
 ///     )
 ///     .expect("Failed to add file watch");
 ///
@@ -221,7 +221,7 @@ impl Inotify {
     /// ```
     /// use inotify::{
     ///     Inotify,
-    ///     watch_mask,
+    ///     WatchMask,
     /// };
     ///
     /// let mut inotify = Inotify::init()
@@ -232,7 +232,7 @@ impl Inotify {
     /// # File::create("/tmp/inotify-rs-test-file")
     /// #     .expect("Failed to create test file");
     /// #
-    /// inotify.add_watch("/tmp/inotify-rs-test-file", watch_mask::MODIFY)
+    /// inotify.add_watch("/tmp/inotify-rs-test-file", WatchMask::MODIFY)
     ///     .expect("Failed to add file watch");
     ///
     /// // Handle events for the file here
@@ -287,8 +287,8 @@ impl Inotify {
     /// #
     /// # // Add a watch and modify the file, so the code below doesn't block
     /// # // forever.
-    /// # use inotify::watch_mask;
-    /// # inotify.add_watch("/tmp/inotify-rs-test-file", watch_mask::MODIFY)
+    /// # use inotify::WatchMask;
+    /// # inotify.add_watch("/tmp/inotify-rs-test-file", WatchMask::MODIFY)
     /// #     .expect("Failed to add file watch");
     /// # use std::io::Write;
     /// # write!(&mut test_file, "something\n")
@@ -518,94 +518,81 @@ impl IntoRawFd for Inotify {
 }
 
 
-/// Contains the [`WatchMask`] flags
-///
-/// Contains constants for all valid [`WatchMask`] flags, which can be used to
-/// compare against a [`WatchMask`] instance using [`WatchMask::contains`].
-///
-/// [`WatchMask`]: struct.WatchMask.html
-/// [`WatchMask::contains`]: struct.WatchMask.html#method.contains
-pub mod watch_mask {
-    use ffi;
-
-    bitflags! {
-        /// Mask for a file watch
-        ///
-        /// Passed to [`Inotify::add_watch`], to describe what file system
-        /// events to watch for and how to do that.
-        ///
-        /// [`Inotify::add_watch`]: ../struct.Inotify.html#method.add_watch
-        pub struct WatchMask: u32 {
-            /// File was accessed.
-            const ACCESS        = ffi::IN_ACCESS;
+bitflags! {
+    /// Mask for a file watch
+    ///
+    /// Passed to [`Inotify::add_watch`], to describe what file system
+    /// events to watch for and how to do that.
+    ///
+    /// [`Inotify::add_watch`]: ../struct.Inotify.html#method.add_watch
+    pub struct WatchMask: u32 {
+        /// File was accessed.
+        const ACCESS        = ffi::IN_ACCESS;
 
-            /// Metadata changed.
-            const ATTRIB        = ffi::IN_ATTRIB;
+        /// Metadata changed.
+        const ATTRIB        = ffi::IN_ATTRIB;
 
-            /// File opened for writing was closed.
-            const CLOSE_WRITE   = ffi::IN_CLOSE_WRITE;
+        /// File opened for writing was closed.
+        const CLOSE_WRITE   = ffi::IN_CLOSE_WRITE;
 
-            /// File or directory not opened for writing was closed.
-            const CLOSE_NOWRITE = ffi::IN_CLOSE_NOWRITE;
+        /// File or directory not opened for writing was closed.
+        const CLOSE_NOWRITE = ffi::IN_CLOSE_NOWRITE;
 
-            /// File/directory created in watched directory.
-            const CREATE        = ffi::IN_CREATE;
+        /// File/directory created in watched directory.
+        const CREATE        = ffi::IN_CREATE;
 
-            /// File/directory deleted from watched directory.
-            const DELETE        = ffi::IN_DELETE;
+        /// File/directory deleted from watched directory.
+        const DELETE        = ffi::IN_DELETE;
 
-            /// Watched file/directory was itself deleted.
-            const DELETE_SELF   = ffi::IN_DELETE_SELF;
+        /// Watched file/directory was itself deleted.
+        const DELETE_SELF   = ffi::IN_DELETE_SELF;
 
-            /// File was modified.
-            const MODIFY        = ffi::IN_MODIFY;
+        /// File was modified.
+        const MODIFY        = ffi::IN_MODIFY;
 
-            /// Watched file/directory was itself moved.
-            const MOVE_SELF     = ffi::IN_MOVE_SELF;
+        /// Watched file/directory was itself moved.
+        const MOVE_SELF     = ffi::IN_MOVE_SELF;
 
-            /// Generated for the directory containing the old filename when a
-            /// file is renamend.
-            const MOVED_FROM    = ffi::IN_MOVED_FROM;
+        /// Generated for the directory containing the old filename when a
+        /// file is renamend.
+        const MOVED_FROM    = ffi::IN_MOVED_FROM;
 
-            /// Generated for the directory containing the new filename when a
-            /// file is renamed.
-            const MOVED_TO      = ffi::IN_MOVED_TO;
+        /// Generated for the directory containing the new filename when a
+        /// file is renamed.
+        const MOVED_TO      = ffi::IN_MOVED_TO;
 
-            /// File or directory was opened.
-            const OPEN          = ffi::IN_OPEN;
+        /// File or directory was opened.
+        const OPEN          = ffi::IN_OPEN;
 
-            /// Watch for all events.
-            const ALL_EVENTS    = ffi::IN_ALL_EVENTS;
+        /// Watch for all events.
+        const ALL_EVENTS    = ffi::IN_ALL_EVENTS;
 
-            /// Watch for both `MOVED_FROM` and `MOVED_TO`.
-            const MOVE          = ffi::IN_MOVE;
+        /// Watch for both `MOVED_FROM` and `MOVED_TO`.
+        const MOVE          = ffi::IN_MOVE;
 
-            /// Watch for both `IN_CLOSE_WRITE` and `IN_CLOSE_NOWRITE`.
-            const CLOSE         = ffi::IN_CLOSE;
+        /// Watch for both `IN_CLOSE_WRITE` and `IN_CLOSE_NOWRITE`.
+        const CLOSE         = ffi::IN_CLOSE;
 
-            /// Don't dereference the path if it is a symbolic link
-            const DONT_FOLLOW   = ffi::IN_DONT_FOLLOW;
+        /// Don't dereference the path if it is a symbolic link
+        const DONT_FOLLOW   = ffi::IN_DONT_FOLLOW;
 
-            /// Don't watch events for children that have been unlinked from
-            /// watched directory.
-            const EXCL_UNLINK   = ffi::IN_EXCL_UNLINK;
+        /// Don't watch events for children that have been unlinked from
+        /// watched directory.
+        const EXCL_UNLINK   = ffi::IN_EXCL_UNLINK;
 
-            /// If a watch instance already exists for the inode corresponding
-            /// to the given path, amend the existing watch mask instead of
-            /// replacing it.
-            const MASK_ADD      = ffi::IN_MASK_ADD;
+        /// If a watch instance already exists for the inode corresponding
+        /// to the given path, amend the existing watch mask instead of
+        /// replacing it.
+        const MASK_ADD      = ffi::IN_MASK_ADD;
 
-            /// Only monitor for one event, then remove the watch
-            const ONESHOT       = ffi::IN_ONESHOT;
+        /// Only monitor for one event, then remove the watch
+        const ONESHOT       = ffi::IN_ONESHOT;
 
-            /// Only watch path, if it is a directory.
-            const ONLYDIR       = ffi::IN_ONLYDIR;
-        }
+        /// Only watch path, if it is a directory.
+        const ONLYDIR       = ffi::IN_ONLYDIR;
     }
 }
 
-pub use self::watch_mask::WatchMask;
-
 
 /// Represents a file that inotify is watching
 ///
@@ -839,78 +826,65 @@ impl<'a> Event<'a> {
 }
 
 
-/// Contains the [`EventMask`] flags
-///
-/// Contains constants for all valid [`EventMask`] flags, which can be used to
-/// compare against a [`EventMask`] instance using [`EventMask::contains`].
-///
-/// [`EventMask`]: struct.EventMask.html
-/// [`EventMask::contains`]: struct.EventMask.html#method.contains
-pub mod event_mask {
-    use ffi;
-
-    bitflags! {
-        /// Mask for an event
-        ///
-        /// This struct can be retrieved from an [`Event`] via its `mask` field.
-        /// You can determine the [`Event`]'s type by comparing it to the
-        /// constants in [this module] module using [`EventMask::contains`].
-        ///
-        /// [`Event`]: ../struct.Event.html
-        /// [this module]: index.html
-        /// [`EventMask::contains`]: struct.EventMask.html#method.contains
-        pub struct EventMask: u32 {
-            /// File was accessed.
-            const ACCESS        = ffi::IN_ACCESS;
+bitflags! {
+    /// Mask for an event
+    ///
+    /// This struct can be retrieved from an [`Event`] via its `mask` field.
+    /// You can determine the [`Event`]'s type by comparing it to the
+    /// constants in [this module] module using [`EventMask::contains`].
+    ///
+    /// [`Event`]: ../struct.Event.html
+    /// [this module]: index.html
+    /// [`EventMask::contains`]: struct.EventMask.html#method.contains
+    pub struct EventMask: u32 {
+        /// File was accessed.
+        const ACCESS        = ffi::IN_ACCESS;
 
-            /// Metadata changed.
-            const ATTRIB        = ffi::IN_ATTRIB;
+        /// Metadata changed.
+        const ATTRIB        = ffi::IN_ATTRIB;
 
-            /// File opened for writing was closed.
-            const CLOSE_WRITE   = ffi::IN_CLOSE_WRITE;
+        /// File opened for writing was closed.
+        const CLOSE_WRITE   = ffi::IN_CLOSE_WRITE;
 
-            /// File or directory not opened for writing was closed.
-            const CLOSE_NOWRITE = ffi::IN_CLOSE_NOWRITE;
+        /// File or directory not opened for writing was closed.
+        const CLOSE_NOWRITE = ffi::IN_CLOSE_NOWRITE;
 
-            /// File/directory created in watched directory.
-            const CREATE        = ffi::IN_CREATE;
+        /// File/directory created in watched directory.
+        const CREATE        = ffi::IN_CREATE;
 
-            /// File/directory deleted from watched directory.
-            const DELETE        = ffi::IN_DELETE;
+        /// File/directory deleted from watched directory.
+        const DELETE        = ffi::IN_DELETE;
 
-            /// Watched file/directory was itself deleted.
-            const DELETE_SELF   = ffi::IN_DELETE_SELF;
+        /// Watched file/directory was itself deleted.
+        const DELETE_SELF   = ffi::IN_DELETE_SELF;
 
-            /// File was modified.
-            const MODIFY        = ffi::IN_MODIFY;
+        /// File was modified.
+        const MODIFY        = ffi::IN_MODIFY;
 
-            /// Watched file/directory was itself moved.
-            const MOVE_SELF     = ffi::IN_MOVE_SELF;
+        /// Watched file/directory was itself moved.
+        const MOVE_SELF     = ffi::IN_MOVE_SELF;
 
-            /// Generated for the directory containing the old filename when a
-            /// file is renamend.
-            const MOVED_FROM    = ffi::IN_MOVED_FROM;
+        /// Generated for the directory containing the old filename when a
+        /// file is renamend.
+        const MOVED_FROM    = ffi::IN_MOVED_FROM;
 
-            /// Generated for the directory containing the new filename when a
-            /// file is renamed.
-            const MOVED_TO      = ffi::IN_MOVED_TO;
+        /// Generated for the directory containing the new filename when a
+        /// file is renamed.
+        const MOVED_TO      = ffi::IN_MOVED_TO;
 
-            /// File or directory was opened.
-            const OPEN          = ffi::IN_OPEN;
+        /// File or directory was opened.
+        const OPEN          = ffi::IN_OPEN;
 
-            /// Watch was removed.
-            const IGNORED       = ffi::IN_IGNORED;
+        /// Watch was removed.
+        const IGNORED       = ffi::IN_IGNORED;
 
-            /// Subject of this event is a directory.
-            const ISDIR         = ffi::IN_ISDIR;
+        /// Subject of this event is a directory.
+        const ISDIR         = ffi::IN_ISDIR;
 
-            /// Event queue overflowed.
-            const Q_OVERFLOW    = ffi::IN_Q_OVERFLOW;
+        /// Event queue overflowed.
+        const Q_OVERFLOW    = ffi::IN_Q_OVERFLOW;
 
-            /// File system containing watched object was unmounted.
-            const UNMOUNT       = ffi::IN_UNMOUNT;
-        }
+        /// File system containing watched object was unmounted.
+        const UNMOUNT       = ffi::IN_UNMOUNT;
     }
 }
-
-pub use self::event_mask::EventMask;


Test patch:
diff --git a/tests/main.rs b/tests/main.rs
index 05fb761..3d86185 100644
--- a/tests/main.rs
+++ b/tests/main.rs
@@ -8,8 +8,8 @@ extern crate inotify;
 extern crate tempdir;
 
 use inotify::{
-    watch_mask,
     Inotify,
+    WatchMask,
 };
 use std::fs::File;
 use std::io::{
@@ -31,7 +31,7 @@ fn it_should_watch_a_file() {
     let (path, mut file) = testdir.new_file();
 
     let mut inotify = Inotify::init().unwrap();
-    let watch = inotify.add_watch(&path, watch_mask::MODIFY).unwrap();
+    let watch = inotify.add_watch(&path, WatchMask::MODIFY).unwrap();
 
     write_to(&mut file);
 
@@ -60,7 +60,7 @@ fn it_should_convert_the_name_into_an_os_str() {
     let (path, mut file) = testdir.new_file();
 
     let mut inotify = Inotify::init().unwrap();
-    inotify.add_watch(&path.parent().unwrap(), watch_mask::MODIFY).unwrap();
+    inotify.add_watch(&path.parent().unwrap(), WatchMask::MODIFY).unwrap();
 
     write_to(&mut file);
 
@@ -81,7 +81,7 @@ fn it_should_set_name_to_none_if_it_is_empty() {
     let (path, mut file) = testdir.new_file();
 
     let mut inotify = Inotify::init().unwrap();
-    inotify.add_watch(&path, watch_mask::MODIFY).unwrap();
+    inotify.add_watch(&path, WatchMask::MODIFY).unwrap();
 
     write_to(&mut file);
 
@@ -102,10 +102,10 @@ fn it_should_not_accept_watchdescriptors_from_other_instances() {
     let (path, _) = testdir.new_file();
 
     let mut inotify = Inotify::init().unwrap();
-    let _ = inotify.add_watch(&path, watch_mask::ACCESS).unwrap();
+    let _ = inotify.add_watch(&path, WatchMask::ACCESS).unwrap();
 
     let mut second_inotify = Inotify::init().unwrap();
-    let wd2 = second_inotify.add_watch(&path, watch_mask::ACCESS).unwrap();
+    let wd2 = second_inotify.add_watch(&path, WatchMask::ACCESS).unwrap();
 
     assert_eq!(inotify.rm_watch(wd2).unwrap_err().kind(), ErrorKind::InvalidInput);
 }
@@ -121,10 +121,10 @@ fn watch_descriptors_from_different_inotify_instances_should_not_be_equal() {
         .unwrap();
 
     let wd_1 = inotify_1
-        .add_watch(&path, watch_mask::ACCESS)
+        .add_watch(&path, WatchMask::ACCESS)
         .unwrap();
     let wd_2 = inotify_2
-        .add_watch(&path, watch_mask::ACCESS)
+        .add_watch(&path, WatchMask::ACCESS)
         .unwrap();
 
     // As far as inotify is concerned, watch descriptors are just integers that
@@ -150,7 +150,7 @@ fn watch_descriptor_equality_should_not_be_confused_by_reused_fds() {
             .unwrap();
 
         let wd_1 = inotify_1
-            .add_watch(&path, watch_mask::ACCESS)
+            .add_watch(&path, WatchMask::ACCESS)
             .unwrap();
         let fd_1 = inotify_1.as_raw_fd();
 
@@ -166,7 +166,7 @@ fn watch_descriptor_equality_should_not_be_confused_by_reused_fds() {
     };
 
     let wd_2 = inotify_2
-        .add_watch(&path, watch_mask::ACCESS)
+        .add_watch(&path, WatchMask::ACCESS)
         .unwrap();
 
     // The way we engineered this situation, both `WatchDescriptor` instances