playdate_device/serial/
async.rs

1#![cfg(feature = "tokio-serial")]
2#![cfg(feature = "tokio")]
3
4use std::ops::DerefMut;
5
6use tokio::io::AsyncWriteExt;
7
8use crate::error::Error;
9use super::Interface;
10
11
12impl crate::interface::r#async::Out for Interface {
13	#[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))]
14	async fn send(&self, data: &[u8]) -> Result<usize, Error> {
15		trace!("writing {} bytes to {}", data.len(), self.info.port_name);
16		if let Some(ref port) = self.port {
17			let mut port = port.try_borrow_mut()?;
18			let port = port.deref_mut();
19			port.write_all(data).await?;
20			port.flush().await?;
21			Ok(data.len())
22		} else {
23			Err(Error::not_ready())
24		}
25	}
26}
27
28
29impl crate::interface::r#async::In for Interface {}