serialplugin_core/cmux/
io.rs1#[cfg(target_os = "ios")]
3use crate::serialport;
4
5use serialport::SerialPort;
6use std::io::Write;
7use std::sync::{Arc, Mutex};
8
9pub trait CmuxPhysicalIo: Send + Sync {
11 fn write_all(&self, data: &[u8]) -> Result<(), String>;
12}
13
14pub struct SerialPortIo(pub Arc<Mutex<Box<dyn SerialPort>>>);
15
16impl CmuxPhysicalIo for SerialPortIo {
17 fn write_all(&self, data: &[u8]) -> Result<(), String> {
18 self.0
19 .lock()
20 .map_err(|e| format!("port lock failed: {e}"))?
21 .write_all(data)
22 .map_err(|e| format!("cmux write failed: {e}"))
23 }
24}