zero_mysql/protocol/trait/
mod.rs

1pub mod param;
2
3use crate::error::Result;
4use crate::protocol::command::ColumnDefinition;
5use crate::protocol::response::OkPayloadBytes;
6use crate::protocol::{BinaryRowPayload, TextRowPayload};
7
8/// Trait for decoding a single row from raw bytes
9///
10/// Implementations can maintain state and decode rows into their own structures
11pub trait RowDecoder<'a> {
12    /// The output type produced by decoding a row
13    type Output;
14
15    /// Decode a single row from byte slice
16    ///
17    /// # Arguments
18    /// * `row` - The raw row data to decode
19    ///
20    /// # Returns
21    /// * `Ok(Self::Output)` - Successfully decoded row
22    /// * `Err(Error)` - Decoding failed
23    fn decode_row(&mut self, row: BinaryRowPayload<'a>) -> Result<Self::Output>;
24}
25
26/// Trait that defines event callbacks for binary protocol result sets
27pub trait BinaryResultSetHandler {
28    fn no_result_set(&mut self, ok: OkPayloadBytes) -> Result<()>;
29    fn resultset_start(&mut self, cols: &[ColumnDefinition<'_>]) -> Result<()>;
30    fn row(&mut self, cols: &[ColumnDefinition<'_>], row: BinaryRowPayload<'_>) -> Result<()>;
31    fn resultset_end(&mut self, eof: OkPayloadBytes) -> Result<()>;
32}
33
34/// Trait that defines event callbacks for text protocol result sets
35pub trait TextResultSetHandler {
36    fn no_result_set(&mut self, ok: OkPayloadBytes) -> Result<()>;
37    fn resultset_start(&mut self, cols: &[ColumnDefinition<'_>]) -> Result<()>;
38    fn row(&mut self, cols: &[ColumnDefinition<'_>], row: TextRowPayload<'_>) -> Result<()>;
39    fn resultset_end(&mut self, eof: OkPayloadBytes) -> Result<()>;
40}
41
42#[cfg(test)]
43mod param_test;