Skip to content

Commit

Permalink
Merge pull request #8 from jeandudey/2020_06_20-v0.3.0
Browse files Browse the repository at this point in the history
Release v0.3.0
  • Loading branch information
jeandudey authored Jun 20, 2020
2 parents a395fa6 + b9a2315 commit 0d5a477
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 44 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Unreleased
# 0.3.0

- .github: Add Rust actions ([#5](https://github.com/jeandudey/tokio-udev/pull/5))
- {mio,tokio}-udev: format code with rustfmt ([#4](https://github.com/jeandudey/tokio-udev/pull/4))
Expand All @@ -9,6 +9,7 @@
- {mio,tokio}-udev: update crate descriptions
- {mio,tokio}-udev: apply copyright
- Add LICENSE-MIT and LICENSE-APACHE
- mio-udev: update udev to 0.4 [#8](https://github.com/jeandudey/tokio-udev/pull/8)

# 0.2.0

Expand Down
4 changes: 2 additions & 2 deletions mio-udev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mio-udev"
version = "0.2.0"
version = "0.3.0"
authors = ["Jean Pierre Dudey <[email protected]>"]
license = "Apache-2.0/MIT"
description = """
Expand All @@ -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"
37 changes: 21 additions & 16 deletions mio-udev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -58,58 +58,63 @@ pub struct MonitorBuilder {
impl MonitorBuilder {
/// Creates a new `MonitorSocket`.
#[inline(always)]
pub fn new(context: &Context) -> io::Result<Self> {
pub fn new() -> io::Result<Self> {
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<T>(&mut self, subsystem: T) -> io::Result<()>
pub fn match_subsystem<T>(self, subsystem: T) -> io::Result<Self>
where
T: AsRef<OsStr>,
{
Ok(self.builder.match_subsystem::<T>(subsystem)?)
self.builder.match_subsystem::<T>(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<T, U>(
&mut self,
self,
subsystem: T,
devtype: U,
) -> io::Result<()>
) -> io::Result<Self>
where
T: AsRef<OsStr>,
U: AsRef<OsStr>,
{
Ok(self
.builder
.match_subsystem_devtype::<T, U>(subsystem, devtype)?)
self.builder
.match_subsystem_devtype::<T, U>(subsystem, devtype)
.map(Self::map)
}

/// Adds a filter that matches events for devices with the given tag.
#[inline(always)]
pub fn match_tag<T>(&mut self, tag: T) -> io::Result<()>
pub fn match_tag<T>(self, tag: T) -> io::Result<Self>
where
T: AsRef<OsStr>,
{
Ok(self.builder.match_tag::<T>(tag)?)
self.builder.match_tag::<T>(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> {
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<MonitorSocket> {
Ok(MonitorSocket::new(self.builder.listen()?)?)
MonitorSocket::new(self.builder.listen()?)
}
}

Expand Down
6 changes: 2 additions & 4 deletions tokio-udev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tokio-udev"
version = "0.2.0"
version = "0.3.0"
authors = ["Jean Pierre Dudey <[email protected]>"]
license = "Apache-2.0/MIT"
description = """
Expand All @@ -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"] }
Expand Down
11 changes: 5 additions & 6 deletions tokio-udev/examples/usb_hotplug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
34 changes: 19 additions & 15 deletions tokio-udev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,51 +57,55 @@ pub struct MonitorBuilder {
impl MonitorBuilder {
/// Creates a new `MonitorSocket`.
#[inline(always)]
pub fn new(context: &mio_udev::Context) -> io::Result<Self> {
pub fn new() -> io::Result<Self> {
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<T>(&mut self, subsystem: T) -> io::Result<()>
pub fn match_subsystem<T>(self, subsystem: T) -> io::Result<Self>
where
T: AsRef<OsStr>,
{
Ok(self.builder.match_subsystem::<T>(subsystem)?)
self.builder.match_subsystem::<T>(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<T, U>(
&mut self,
self,
subsystem: T,
devtype: U,
) -> io::Result<()>
) -> io::Result<Self>
where
T: AsRef<OsStr>,
U: AsRef<OsStr>,
{
Ok(self
.builder
.match_subsystem_devtype::<T, U>(subsystem, devtype)?)
self.builder
.match_subsystem_devtype::<T, U>(subsystem, devtype)
.map(Self::map)
}

/// Adds a filter that matches events for devices with the given tag.
#[inline(always)]
pub fn match_tag<T>(&mut self, tag: T) -> io::Result<()>
pub fn match_tag<T>(self, tag: T) -> io::Result<Self>
where
T: AsRef<OsStr>,
{
Ok(self.builder.match_tag::<T>(tag)?)
self.builder.match_tag::<T>(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> {
self.builder.clear_filters().map(Self::map)
}

/// Listens for events matching the current filters.
Expand Down

0 comments on commit 0d5a477

Please sign in to comment.