Skip to main content

serialplugin_core/api/
details.rs

1//! [`SerialManager::available_ports_detailed`].
2
3use crate::error::Error;
4use crate::port::details::PortDetails;
5use crate::SerialManager;
6
7impl SerialManager {
8    /// Every serial port with typed details (numeric vid/pid, USB interface number,
9    /// location, Linux `/dev/serial` links), sorted by path. The 4.x
10    /// [`Self::available_ports`] map is unchanged. On Android the fields come from
11    /// the 4.x map (no interface / location).
12    pub fn available_ports_detailed(&self) -> Result<Vec<PortDetails>, Error> {
13        #[cfg(not(target_os = "android"))]
14        {
15            crate::port::details::available_ports_detailed()
16        }
17        #[cfg(target_os = "android")]
18        {
19            let mut out: Vec<PortDetails> = self
20                .available_ports(false)?
21                .iter()
22                .map(|(path, info)| crate::port::details::details_from_info_map(path.clone(), info))
23                .collect();
24            out.sort_by(|a, b| a.path.cmp(&b.path));
25            Ok(out)
26        }
27    }
28}