pub trait ItemEncoder<T> {
// Required method
fn encode(
&mut self,
item: &T,
index: u64,
buf: &mut BytesMut,
) -> Result<(), StreamError>;
// Provided methods
fn prologue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError> { ... }
fn epilogue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError> { ... }
}Expand description
Per-stream encoding state.
index is passed to encode rather than tracked internally because several formats key
their framing off it: the JSON array writes a separator before every item but the first,
CSV writes its header row only at index 0, and Arrow emits the schema message only at
index 0. Implementations that do not care simply ignore it.
Required Methods§
Provided Methods§
Sourcefn prologue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError>
fn prologue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError>
Bytes emitted before the first item, if any.
Sourcefn epilogue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError>
fn epilogue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError>
Bytes emitted after the last item, if any.
Called on normal end of stream only, never after an error, and never if the stream is dropped, since in both cases the body is already truncated and a well-formed terminator would misrepresent it as complete.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl ItemEncoder<RecordBatch> for ArrowIpcEncoder
Available on crate feature
arrow only.impl ItemEncoder<String> for TextEncoder
Available on crate feature
text only.impl<T> ItemEncoder<T> for CsvEncoderwhere
T: Serialize,
Available on crate feature
csv only.impl<T> ItemEncoder<T> for JsonArrayEncoderwhere
T: Serialize,
Available on crate feature
json only.impl<T> ItemEncoder<T> for JsonNewLineEncoderwhere
T: Serialize,
Available on crate feature
json only.impl<T> ItemEncoder<T> for ProtobufEncoderwhere
T: Message,
Available on crate feature
protobuf only.