udp_request/response/
trait.rs

1use crate::*;
2
3/// A trait for handling UDP responses.
4///
5/// This trait defines the common operations for processing UDP responses,
6/// including converting them to text or binary formats.
7pub trait ResponseTrait: Send + Debug {
8    /// The associated type for the text representation of the response.
9    type OutputText: Clone + Sized;
10    /// The associated type for the binary representation of the response.
11    type OutputBinary: Clone + Sized;
12
13    /// Converts the response to its text format.
14    ///
15    /// # Returns
16    ///
17    /// - `Self::OutputText` - The text representation of the response.
18    fn text(&self) -> Self::OutputText;
19
20    /// Returns the binary representation of the response.
21    ///
22    /// # Returns
23    ///
24    /// - `Self::OutputBinary` - The binary representation of the response.
25    fn binary(&self) -> Self::OutputBinary;
26
27    /// Creates a response instance from a byte slice.
28    ///
29    /// # Arguments
30    ///
31    /// - `&[u8]` - The byte slice containing the response data.
32    ///
33    /// # Returns
34    ///
35    /// - `Self` - A new instance of the response type.
36    fn from(response: &[u8]) -> Self
37    where
38        Self: Sized;
39}