Skip to content

Commit

Permalink
Generate stable port order from list_ports
Browse files Browse the repository at this point in the history
  • Loading branch information
sirhcel committed Oct 14, 2024
1 parent b7e67e4 commit 594ca48
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/list_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ use serialport::{available_ports, SerialPortType};

fn main() {
match available_ports() {
Ok(ports) => {
Ok(mut ports) => {
// Let's output ports in a stable order to facilitate comparing the output from
// different runs (on different platforms, with different features, ...).
ports.sort_by_key(|i| i.port_name.clone());

match ports.len() {
0 => println!("No ports found."),
1 => println!("Found 1 port:"),
n => println!("Found {} ports:", n),
};

for p in ports {
println!(" {}", p.port_name);
match p.port_type {
Expand Down

0 comments on commit 594ca48

Please sign in to comment.