1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use core::task::{Context, Poll};
use crate::backend::{Encode, FormatSerialize};
use crate::io;
pub struct SerializeAll<'w, F, W, Dta, Enc>
where
Dta: ?Sized,
{
format: &'w F,
writer: &'w mut W,
data: &'w Dta,
encoder: Enc,
}
impl<'w, F, W, Dta, Enc> SerializeAll<'w, F, W, Dta, Enc>
where
Dta: ?Sized,
{
pub fn new(format: &'w F, writer: &'w mut W, data: &'w Dta, encoder: Enc) -> Self {
Self{
format,
writer,
data,
encoder,
}
}
}
impl<'w, F, W, Dta, Enc> Unpin for SerializeAll<'w, F, W, Dta, Enc>
where
Dta: ?Sized,
{}
impl<'w, F, W, Dta, Enc> core::future::Future for SerializeAll<'w, F, W, Dta, Enc>
where
F: FormatSerialize,
W: io::AsyncWrite + Unpin,
Dta: ?Sized,
Enc: Encode<Format=F, Data=Dta>,
{
type Output = Result<(), F::Error>;
fn poll(mut self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = &mut *self;
this.encoder.poll_encode(this.format, &mut this.writer, this.data, cx).into()
}
}