From 31e0794e79daec4f990acc2b6cbf41a48283cebb Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 12 Jan 2025 20:51:17 +0100 Subject: Simplify some std examples. --- examples/std/src/bin/net_ppp.rs | 52 +---------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) (limited to 'examples/std/src/bin/net_ppp.rs') diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index ea3fbebef..f667e8d4c 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs @@ -45,7 +45,7 @@ async fn net_task(mut runner: embassy_net::Runner<'static, embassy_net_ppp::Devi async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: SerialPort) -> ! { let port = Async::new(port).unwrap(); let port = BufReader::new(port); - let port = adapter::FromFutures::new(port); + let port = embedded_io_adapters::futures_03::FromFutures::new(port); let config = embassy_net_ppp::Config { username: b"myuser", @@ -163,53 +163,3 @@ fn main() { spawner.spawn(main_task(spawner)).unwrap(); }); } - -mod adapter { - use core::future::poll_fn; - use core::pin::Pin; - - use futures::AsyncBufReadExt; - - /// Adapter from `futures::io` traits. - #[derive(Clone)] - pub struct FromFutures { - inner: T, - } - - impl FromFutures { - /// Create a new adapter. - pub fn new(inner: T) -> Self { - Self { inner } - } - } - - impl embedded_io_async::ErrorType for FromFutures { - type Error = std::io::Error; - } - - impl embedded_io_async::Read for FromFutures { - async fn read(&mut self, buf: &mut [u8]) -> Result { - poll_fn(|cx| Pin::new(&mut self.inner).poll_read(cx, buf)).await - } - } - - impl embedded_io_async::BufRead for FromFutures { - async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { - self.inner.fill_buf().await - } - - fn consume(&mut self, amt: usize) { - Pin::new(&mut self.inner).consume(amt) - } - } - - impl embedded_io_async::Write for FromFutures { - async fn write(&mut self, buf: &[u8]) -> Result { - poll_fn(|cx| Pin::new(&mut self.inner).poll_write(cx, buf)).await - } - - async fn flush(&mut self) -> Result<(), Self::Error> { - poll_fn(|cx| Pin::new(&mut self.inner).poll_flush(cx)).await - } - } -} -- cgit