serialplugin_core/cmux/
path.rs1pub fn mux_path(physical: &str, dlci: u8) -> String {
5 format!("{physical}#dlci={dlci}")
6}
7
8pub fn is_data_dlci(dlci: u8) -> bool {
10 (1..=63).contains(&dlci)
11}
12
13pub fn parse_mux_path(path: &str) -> Option<(&str, u8)> {
15 let (base, dlci_str) = path.rsplit_once("#dlci=")?;
16 dlci_str
17 .parse()
18 .ok()
19 .filter(|&d| is_data_dlci(d))
20 .map(|dlci| (base, dlci))
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn mux_path_roundtrip() {
29 let p = mux_path("/dev/ttyUSB0", 1);
30 assert_eq!(parse_mux_path(&p), Some(("/dev/ttyUSB0", 1)));
31 assert_eq!(parse_mux_path("/dev/ttyUSB0#dlci=0"), None);
32 assert_eq!(parse_mux_path("/dev/ttyUSB0#dlci=65"), None);
33 }
34}