embedded_platform/io/
read.rs1use core::future;
2use core::pin;
3use core::task;
4
5#[derive(Debug)]
6#[must_use = "futures do nothing unless you `.await` or poll them"]
7pub struct Read<'a, A>
8where
9 A: super::Read + Unpin + ?Sized,
10{
11 reader: &'a mut A,
12 buffer: &'a mut [u8],
13 position: usize,
14}
15
16pub fn read<'a, A>(reader: &'a mut A, buffer: &'a mut [u8]) -> Read<'a, A>
17where
18 A: super::Read + Unpin + ?Sized,
19{
20 let position = 0;
21 Read {
22 reader,
23 buffer,
24 position,
25 }
26}
27
28impl<A> future::Future for Read<'_, A>
29where
30 A: super::Read + Unpin + ?Sized,
31{
32 type Output = Result<usize, A::Error>;
33
34 fn poll(mut self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
35 let this = &mut *self;
36 pin::Pin::new(&mut *this.reader).poll_read(cx, this.buffer)
37 }
38}