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 |
+------+--------+------------------+-----------+
| COM4 | wch.cn | USB-SERIAL CH340 | 1A86:7523 |
+------+--------+------------------+-----------+