Skip to content

Commit

Permalink
Add support for mio 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Meer authored and Drakulix committed Jul 10, 2024
1 parent ad2b07b commit 0ab69a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ jobs:
- --no-default-features --features "mio06"
- --no-default-features --features "mio07"
- --no-default-features --features "mio08"
- --no-default-features --features "mio10"
- --no-default-features --features "hwdb"
- '' # default
include:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ libc = "0.2"
mio06 = { package = "mio", version = "^0.6.21", optional = true }
mio07 = { package = "mio", version = "0.7", features = ["os-ext"], optional = true }
mio08 = { package = "mio", version = "0.8", features = ["os-ext"], optional = true }
mio10 = { package = "mio", version = "1.0", features = ["os-ext"], optional = true }

[build-dependencies]
pkg-config = "0.3.3" #force a newer version for libudev-sys to fix minimal versions

[features]
mio = ["mio08"] # mio feature defaults to the newest mio version
mio = ["mio10"] # mio feature defaults to the newest mio version
hwdb = []
17 changes: 14 additions & 3 deletions examples/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ extern crate mio06;
extern crate mio07;
#[cfg(feature = "mio08")]
extern crate mio08;
#[cfg(feature = "mio10")]
extern crate mio10;
extern crate udev;

use std::io;

#[cfg(not(any(feature = "mio06", feature = "mio07", feature = "mio08")))]
#[cfg(not(any(
feature = "mio06",
feature = "mio07",
feature = "mio08",
feature = "mio10"
)))]
mod poll {
use std::io;
use std::ptr;
Expand Down Expand Up @@ -114,20 +121,24 @@ mod poll {
}
}

#[cfg(any(feature = "mio07", feature = "mio08"))]
#[cfg(any(feature = "mio07", feature = "mio08", feature = "mio10"))]
mod poll {
use std::io;

#[cfg(feature = "mio07")]
use mio07::{Events, Interest, Poll, Token};
#[cfg(feature = "mio08")]
use mio08::{Events, Interest, Poll, Token};
#[cfg(feature = "mio10")]
use mio10::{Events, Interest, Poll, Token};

pub fn poll(mut socket: udev::MonitorSocket) -> io::Result<()> {
let version = if cfg!(feature = "mio07") {
"mio07"
} else if cfg!(feature = "mio08") {
"mio08"
} else if cfg!(feature = "mio10") {
"mio10"
} else {
"mio-unknown"
};
Expand Down Expand Up @@ -169,7 +180,7 @@ fn print_event(event: udev::Event) {
}

// Use `mio::poll` as poller by compile with:
// `cargo run --example monitor --features "mio08"`
// `cargo run --example monitor --features "mio10"`
fn main() -> io::Result<()> {
let socket = udev::MonitorBuilder::new()?
// .match_subsystem_devtype("usb", "usb_device")?
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern crate mio06;
extern crate mio07;
#[cfg(feature = "mio08")]
extern crate mio08;
#[cfg(feature = "mio10")]
extern crate mio10;

pub use device::{Attributes, Device, DeviceType, Properties};
pub use enumerator::{Devices, Enumerator};
Expand Down
4 changes: 3 additions & 1 deletion src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use mio06::{event::Evented, unix::EventedFd, Poll, PollOpt, Ready, Token};
use mio07::{event::Source, unix::SourceFd, Interest, Registry, Token};
#[cfg(feature = "mio08")]
use mio08::{event::Source, unix::SourceFd, Interest, Registry, Token};
#[cfg(feature = "mio10")]
use mio10::{event::Source, unix::SourceFd, Interest, Registry, Token};

use Udev;
use {ffi, util};
Expand Down Expand Up @@ -334,7 +336,7 @@ impl Evented for Socket {
}
}

#[cfg(any(feature = "mio07", feature = "mio08"))]
#[cfg(any(feature = "mio07", feature = "mio08", feature = "mio10"))]
impl Source for Socket {
fn register(
&mut self,
Expand Down

0 comments on commit 0ab69a0

Please sign in to comment.