embedded_platform/io/
write.rs

1use 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 Write<'a, A: ?Sized> {
8    writer: &'a mut A,
9    buf: &'a [u8],
10}
11pub(crate) fn write<'a, A>(writer: &'a mut A, buf: &'a [u8]) -> Write<'a, A>
12where
13    A: super::Write + Unpin + ?Sized,
14{
15    Write { writer, buf }
16}
17
18impl<A> future::Future for Write<'_, A>
19where
20    A: super::Write + Unpin + ?Sized,
21{
22    type Output = Result<usize, A::Error>;
23
24    fn poll(mut self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
25        let this = &mut *self;
26        pin::Pin::new(&mut *this.writer).poll_write(cx, this.buf)
27    }
28}