A serial port enumreator library writen in rust, which can help you to get serial ports and informations of you devices.
```rust use clitable::{format::Justify, printstdout, Table, WithTitle}; use serialenumerator::{getserial_list, SerialInfo};
struct SerialItem { #[table(title = "Name")] name: String, #[table(title = "Vendor", justify = "Justify::Center")] vendor: String, #[table(title = "Product", justify = "Justify::Center")] product: String, #[table(title = "USB", justify = "Justify::Center")] usb: String, }
impl SerialItem { pub fn fromserialinfo(serialinfo: SerialInfo) -> SerialItem { let fieldorelse = || Some(String::from("--")); return SerialItem { name: serialinfo.name, vendor: serialinfo.vendor.orelse(fieldorelse).unwrap(), product: serialinfo.product.orelse(fieldorelse).unwrap(), usb: serialinfo .usbinfo .andthen(|usbinfo| Some(format!("{}:{}", usbinfo.vid, usbinfo.pid))) .orelse(fieldorelse) .unwrap(), }; } }
fn main() { let serialsinfo = getseriallist(); let mut serialstable = Vec::new(); for serialinfo in serialsinfo { serialstable.push(SerialItem::fromserialinfo(serialinfo)); } printstdout(serialstable.with_title()).unwrap(); }
```
bash
+--------------+------------+------------------+-----------+
| Name | Vendor | Product | USB |
+--------------+------------+------------------+-----------+
| /dev/ttyS0 | pnp | PNP0501 | -- |
+--------------+------------+------------------+-----------+
| /dev/ttyUSB0 | FTDI | Dual RS232-HS:00 | 0403:6010 |
+--------------+------------+------------------+-----------+
| /dev/ttyUSB1 | FTDI | Dual RS232-HS:01 | 0403:6010 |
+--------------+------------+------------------+-----------+
| /dev/ttyUSB2 | ch341-uart | USB2.0-Serial:00 | 1a86:7523 |
+--------------+------------+------------------+-----------+