From 96fdb1f7c1836b28037c8988cbab3106fe917eba Mon Sep 17 00:00:00 2001 From: Jean Pierre Dudey Date: Sat, 20 Jun 2020 16:28:36 -0500 Subject: [PATCH] mio-udev: update udev to 0.4 Signed-off-by: Jean Pierre Dudey --- mio-udev/Cargo.toml | 4 ++-- mio-udev/src/lib.rs | 37 +++++++++++++++++------------- tokio-udev/Cargo.toml | 6 ++--- tokio-udev/examples/usb_hotplug.rs | 11 ++++----- tokio-udev/src/lib.rs | 34 +++++++++++++++------------ 5 files changed, 49 insertions(+), 43 deletions(-) diff --git a/mio-udev/Cargo.toml b/mio-udev/Cargo.toml index 9f579b8..b92717b 100644 --- a/mio-udev/Cargo.toml +++ b/mio-udev/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mio-udev" -version = "0.2.0" +version = "0.3.0" authors = ["Jean Pierre Dudey "] license = "Apache-2.0/MIT" description = """ @@ -12,6 +12,6 @@ documentation = "https://docs.rs/mio-udev" edition = "2018" [dependencies] -udev = "0.2" +udev = "0.4" mio = "0.6" libc = "0.2" diff --git a/mio-udev/src/lib.rs b/mio-udev/src/lib.rs index 5637853..d6be74b 100644 --- a/mio-udev/src/lib.rs +++ b/mio-udev/src/lib.rs @@ -31,8 +31,8 @@ #![cfg(target_os = "linux")] pub use udev::{ - Attribute, Attributes, Context, Device, Enumerator, Error as UdevError, - Event, EventType, Properties, Property, + Attribute, Attributes, Device, Enumerator, Event, EventType, Properties, + Property, }; mod util; @@ -58,58 +58,63 @@ pub struct MonitorBuilder { impl MonitorBuilder { /// Creates a new `MonitorSocket`. #[inline(always)] - pub fn new(context: &Context) -> io::Result { + pub fn new() -> io::Result { Ok(MonitorBuilder { - builder: udev::MonitorBuilder::new(context)?, + builder: udev::MonitorBuilder::new()?, }) } + #[inline(always)] + fn map(builder: udev::MonitorBuilder) -> Self { + MonitorBuilder { builder } + } + /// Adds a filter that matches events for devices with the given subsystem. #[inline(always)] - pub fn match_subsystem(&mut self, subsystem: T) -> io::Result<()> + pub fn match_subsystem(self, subsystem: T) -> io::Result where T: AsRef, { - Ok(self.builder.match_subsystem::(subsystem)?) + self.builder.match_subsystem::(subsystem).map(Self::map) } /// Adds a filter that matches events for devices with the given subsystem /// and device type. #[inline(always)] pub fn match_subsystem_devtype( - &mut self, + self, subsystem: T, devtype: U, - ) -> io::Result<()> + ) -> io::Result where T: AsRef, U: AsRef, { - Ok(self - .builder - .match_subsystem_devtype::(subsystem, devtype)?) + self.builder + .match_subsystem_devtype::(subsystem, devtype) + .map(Self::map) } /// Adds a filter that matches events for devices with the given tag. #[inline(always)] - pub fn match_tag(&mut self, tag: T) -> io::Result<()> + pub fn match_tag(self, tag: T) -> io::Result where T: AsRef, { - Ok(self.builder.match_tag::(tag)?) + self.builder.match_tag::(tag).map(Self::map) } /// Removes all filters currently set on the monitor. #[inline(always)] - pub fn clear_filters(&mut self) -> io::Result<()> { - Ok(self.builder.clear_filters()?) + pub fn clear_filters(self) -> io::Result { + self.builder.clear_filters().map(Self::map) } /// Listens for events matching the current filters. /// /// This method consumes the `MonitorBuilder`. pub fn listen(self) -> io::Result { - Ok(MonitorSocket::new(self.builder.listen()?)?) + MonitorSocket::new(self.builder.listen()?) } } diff --git a/tokio-udev/Cargo.toml b/tokio-udev/Cargo.toml index 26b096e..8a85a33 100644 --- a/tokio-udev/Cargo.toml +++ b/tokio-udev/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tokio-udev" -version = "0.2.0" +version = "0.3.0" authors = ["Jean Pierre Dudey "] license = "Apache-2.0/MIT" description = """ @@ -12,10 +12,8 @@ documentation = "https://docs.rs/tokio-udev" edition = "2018" [dependencies] -libc = "0.2" - mio = "0.6" -mio-udev = { path = "../mio-udev", version = "0.2.0" } +mio-udev = { path = "../mio-udev", version = "0.3.0" } futures-core = "0.3" tokio = { version = "0.2", features = ["io-driver"] } diff --git a/tokio-udev/examples/usb_hotplug.rs b/tokio-udev/examples/usb_hotplug.rs index a3e4914..5e8e44c 100644 --- a/tokio-udev/examples/usb_hotplug.rs +++ b/tokio-udev/examples/usb_hotplug.rs @@ -10,17 +10,16 @@ use futures_util::future::ready; use futures_util::stream::StreamExt; -use tokio_udev::{Context, MonitorBuilder}; +use tokio_udev::MonitorBuilder; #[tokio::main] async fn main() { - let context = Context::new().unwrap(); - let mut builder = MonitorBuilder::new(&context).unwrap(); - builder + let builder = MonitorBuilder::new() + .expect("Couldn't create builder") .match_subsystem_devtype("usb", "usb_device") - .unwrap(); + .expect("Failed to add filter for USB devices"); - let monitor = builder.listen().unwrap(); + let monitor = builder.listen().expect("Couldn't create MonitorSocket"); monitor .for_each(|event| { println!( diff --git a/tokio-udev/src/lib.rs b/tokio-udev/src/lib.rs index e74e9d4..21d8024 100644 --- a/tokio-udev/src/lib.rs +++ b/tokio-udev/src/lib.rs @@ -31,8 +31,8 @@ #![cfg(target_os = "linux")] pub use mio_udev::{ - Attribute, Attributes, Context, Device, Enumerator, Event, EventType, - Properties, Property, UdevError, + Attribute, Attributes, Device, Enumerator, Event, EventType, Properties, + Property, }; use std::ffi::OsStr; @@ -57,51 +57,55 @@ pub struct MonitorBuilder { impl MonitorBuilder { /// Creates a new `MonitorSocket`. #[inline(always)] - pub fn new(context: &mio_udev::Context) -> io::Result { + pub fn new() -> io::Result { Ok(MonitorBuilder { - builder: mio_udev::MonitorBuilder::new(context)?, + builder: mio_udev::MonitorBuilder::new()?, }) } + fn map(builder: mio_udev::MonitorBuilder) -> Self { + MonitorBuilder { builder } + } + /// Adds a filter that matches events for devices with the given subsystem. #[inline(always)] - pub fn match_subsystem(&mut self, subsystem: T) -> io::Result<()> + pub fn match_subsystem(self, subsystem: T) -> io::Result where T: AsRef, { - Ok(self.builder.match_subsystem::(subsystem)?) + self.builder.match_subsystem::(subsystem).map(Self::map) } /// Adds a filter that matches events for devices with the given subsystem /// and device type. #[inline(always)] pub fn match_subsystem_devtype( - &mut self, + self, subsystem: T, devtype: U, - ) -> io::Result<()> + ) -> io::Result where T: AsRef, U: AsRef, { - Ok(self - .builder - .match_subsystem_devtype::(subsystem, devtype)?) + self.builder + .match_subsystem_devtype::(subsystem, devtype) + .map(Self::map) } /// Adds a filter that matches events for devices with the given tag. #[inline(always)] - pub fn match_tag(&mut self, tag: T) -> io::Result<()> + pub fn match_tag(self, tag: T) -> io::Result where T: AsRef, { - Ok(self.builder.match_tag::(tag)?) + self.builder.match_tag::(tag).map(Self::map) } /// Removes all filters currently set on the monitor. #[inline(always)] - pub fn clear_filters(&mut self) -> io::Result<()> { - Ok(self.builder.clear_filters()?) + pub fn clear_filters(self) -> io::Result { + self.builder.clear_filters().map(Self::map) } /// Listens for events matching the current filters.