(&self)
| 585 | if let Some(index) = match_device_index(&names, wanted) { |
| 586 | return devices.get(index); |
| 587 | } |
| 588 | } |
| 589 | devices |
| 590 | .iter() |
| 591 | .find(|device| device.is_default) |
| 592 | .or_else(|| devices.first()) |
| 593 | } |
| 594 | |
| 595 | /// Index of `wanted`: exact match first, then trimmed case-insensitive match. |
| 596 | fn match_device_index(names: &[&str], wanted: &str) -> Option<usize> { |
| 597 | let wanted = wanted.trim(); |
| 598 | if wanted.is_empty() { |
| 599 | return None; |
| 600 | } |
| 601 | names.iter().position(|name| *name == wanted).or_else(|| { |
| 602 | names |
| 603 | .iter() |
| 604 | .position(|name| name.trim().eq_ignore_ascii_case(wanted)) |
| 605 | }) |
| 606 | } |
| 607 | |
| 608 | /// Scan the input devices the OS exposes right now. |
no test coverage detected