aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net_ppp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/std/src/bin/net_ppp.rs')
-rw-r--r--examples/std/src/bin/net_ppp.rs52
1 files changed, 1 insertions, 51 deletions
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
45async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: SerialPort) -> ! { 45async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: SerialPort) -> ! {
46 let port = Async::new(port).unwrap(); 46 let port = Async::new(port).unwrap();
47 let port = BufReader::new(port); 47 let port = BufReader::new(port);
48 let port = adapter::FromFutures::new(port); 48 let port = embedded_io_adapters::futures_03::FromFutures::new(port);
49 49
50 let config = embassy_net_ppp::Config { 50 let config = embassy_net_ppp::Config {
51 username: b"myuser", 51 username: b"myuser",
@@ -163,53 +163,3 @@ fn main() {
163 spawner.spawn(main_task(spawner)).unwrap(); 163 spawner.spawn(main_task(spawner)).unwrap();
164 }); 164 });
165} 165}
166
167mod adapter {
168 use core::future::poll_fn;
169 use core::pin::Pin;
170
171 use futures::AsyncBufReadExt;
172
173 /// Adapter from `futures::io` traits.
174 #[derive(Clone)]
175 pub struct FromFutures<T: ?Sized> {
176 inner: T,
177 }
178
179 impl<T> FromFutures<T> {
180 /// Create a new adapter.
181 pub fn new(inner: T) -> Self {
182 Self { inner }
183 }
184 }
185
186 impl<T: ?Sized> embedded_io_async::ErrorType for FromFutures<T> {
187 type Error = std::io::Error;
188 }
189
190 impl<T: futures::io::AsyncRead + Unpin + ?Sized> embedded_io_async::Read for FromFutures<T> {
191 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
192 poll_fn(|cx| Pin::new(&mut self.inner).poll_read(cx, buf)).await
193 }
194 }
195
196 impl<T: futures::io::AsyncBufRead + Unpin + ?Sized> embedded_io_async::BufRead for FromFutures<T> {
197 async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
198 self.inner.fill_buf().await
199 }
200
201 fn consume(&mut self, amt: usize) {
202 Pin::new(&mut self.inner).consume(amt)
203 }
204 }
205
206 impl<T: futures::io::AsyncWrite + Unpin + ?Sized> embedded_io_async::Write for FromFutures<T> {
207 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
208 poll_fn(|cx| Pin::new(&mut self.inner).poll_write(cx, buf)).await
209 }
210
211 async fn flush(&mut self) -> Result<(), Self::Error> {
212 poll_fn(|cx| Pin::new(&mut self.inner).poll_flush(cx)).await
213 }
214 }
215}