enumerate should return a tuple, (PathBuf, Device)

This commit is contained in:
Wayne Warren 2022-01-16 18:33:52 -07:00
parent 4d957a4dac
commit 07095dbbbc
2 changed files with 8 additions and 7 deletions

View file

@ -87,6 +87,7 @@ pub mod uinput;
mod tokio_stream;
use std::fmt;
use std::path::PathBuf;
use std::time::{Duration, SystemTime};
// pub use crate::constants::FFEffect::*;
@ -249,9 +250,9 @@ pub struct EnumerateDevices {
inner: raw_stream::EnumerateDevices,
}
impl Iterator for EnumerateDevices {
type Item = Device;
fn next(&mut self) -> Option<Device> {
self.inner.next().map(Device::from_raw_device)
type Item = (PathBuf, Device);
fn next(&mut self) -> Option<(PathBuf, Device)> {
self.inner.next().map(|(pb, dev)| (pb, Device::from_raw_device(dev)))
}
}

View file

@ -2,7 +2,7 @@ use std::fs::{File, OpenOptions};
use std::io::Write;
use std::mem::MaybeUninit;
use std::os::unix::io::{AsRawFd, RawFd};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::{io, mem};
use crate::constants::*;
@ -656,8 +656,8 @@ pub struct EnumerateDevices {
readdir: Option<std::fs::ReadDir>,
}
impl Iterator for EnumerateDevices {
type Item = RawDevice;
fn next(&mut self) -> Option<RawDevice> {
type Item = (PathBuf, RawDevice);
fn next(&mut self) -> Option<(PathBuf, RawDevice)> {
use std::os::unix::ffi::OsStrExt;
let readdir = self.readdir.as_mut()?;
loop {
@ -666,7 +666,7 @@ impl Iterator for EnumerateDevices {
let fname = path.file_name().unwrap();
if fname.as_bytes().starts_with(b"event") {
if let Ok(dev) = RawDevice::open(&path) {
return Some(dev);
return Some((path, dev));
}
}
}