diny_core/buffer/
buffer_encode.rs1use core::task::{Context};
2use crate::backend::{self, Encode, Format, FormatEncode};
3use crate::io;
4
5pub trait BufferEncode: Sized {
8 type Format: FormatEncode;
9 type Data;
10
11 fn init_buffer(data: &Self::Data) -> Self;
12
13 fn start_encode_buffer<W>(format: &Self::Format, writer: &mut W, data: &Self::Data, cx: &mut Context<'_>) -> backend::StartEncodeStatus<Self, <<Self as BufferEncode>::Format as Format>::Error>
14 where
15 W: io::AsyncWrite + Unpin,
16 ;
17
18 fn poll_encode_buffer<W>(&mut self, format: &Self::Format, writer: &mut W, cx: &mut Context<'_>) -> backend::PollEncodeStatus<<<Self as BufferEncode>::Format as Format>::Error>
19 where
20 W: io::AsyncWrite + Unpin,
21 ;
22}
23
24impl<T> Encode for T where T: BufferEncode {
25 type Format = T::Format;
26 type Data = T::Data;
27
28 fn init(data: &Self::Data) -> Self {
29 Self::init_buffer(data)
30 }
31
32 fn start_encode<W>(format: &Self::Format, writer: &mut W, data: &Self::Data, cx: &mut Context<'_>) -> backend::StartEncodeStatus<Self, <<Self as BufferEncode>::Format as Format>::Error>
33 where
34 W: io::AsyncWrite + Unpin,
35 {
36 <Self as BufferEncode>::start_encode_buffer(format, writer, data, cx)
37 }
38
39 fn poll_encode<W>(&mut self, format: &Self::Format, writer: &mut W, _data: &Self::Data, cx: &mut Context<'_>) -> backend::PollEncodeStatus<<<Self as BufferEncode>::Format as Format>::Error>
40 where
41 W: io::AsyncWrite + Unpin,
42 {
43 self.poll_encode_buffer(format, writer, cx)
44 }
45}