Skip to content

Commit 9819b13

Browse files
committed
enumerate: handle errors in the doc example better
1 parent 6c91eaf commit 9819b13

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/enumerate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{Evdev, hotplug::HotplugMonitor};
3535
///
3636
/// for res in enumerate()? {
3737
/// let (path, evdev) = res?;
38-
/// println!("{}: {}", path.display(), evdev.name()?);
38+
/// println!("{}: {:?}", path.display(), evdev.name());
3939
/// }
4040
/// # Ok::<_, std::io::Error>(())
4141
/// ```
@@ -65,7 +65,7 @@ pub fn enumerate() -> io::Result<Enumerate> {
6565
///
6666
/// for res in enumerate_hotplug()? {
6767
/// let (path, evdev) = res?;
68-
/// println!("{}: {}", path.display(), evdev.name()?);
68+
/// println!("{}: {:?}", path.display(), evdev.name());
6969
/// }
7070
/// # Ok::<_, std::io::Error>(())
7171
/// ```
@@ -120,6 +120,8 @@ impl Iterator for Enumerate {
120120
Ok(dev) => return Some(Ok((path, dev))),
121121
// If a device is unplugged in the middle of enumeration (before it can be opened),
122122
// skip it, since yielding this error to the application is pretty useless.
123+
// Note that callers still have to handle the device disappearing immediately,
124+
// which is surfaced as getting `ENODEV` from all operations.
123125
Err(e) if e.kind() == io::ErrorKind::NotFound => continue,
124126
Err(e) => return Some(Err(e)),
125127
}

src/evdev.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ impl Evdev {
311311
// `ENODEV` currently has no corresponding `ErrorKind` variant, so wrapping the
312312
// error would make it difficult to detect unplugged devices.
313313
// So instead we just return the original error.
314+
// https://github.com/rust-lang/rust/issues/130193
314315
Err(e)
315316
} else {
316317
// Wrap the original I/O error in `WrappedError` to include additional

0 commit comments

Comments
 (0)