udp_request/response/response_text/impl.rs
1use crate::*;
2
3/// Implements the `ResponseTrait` for `UdpResponseText`.
4impl ResponseTrait for UdpResponseText {
5 type OutputText = UdpResponseText;
6 type OutputBinary = UdpResponseBinary;
7
8 /// Creates a `UdpResponseText` from a byte slice.
9 ///
10 /// This method first converts the byte slice to `UdpResponseBinary`
11 /// and then to `UdpResponseText`.
12 ///
13 /// # Arguments
14 ///
15 /// - `&[u8]` - The byte slice containing the response data.
16 ///
17 /// # Returns
18 ///
19 /// - `Self::OutputText` - The text representation of the response.
20 fn from(response: &[u8]) -> Self::OutputText
21 where
22 Self: Sized,
23 {
24 <UdpResponseBinary as ResponseTrait>::from(response).text()
25 }
26
27 /// Returns the text representation of the response.
28 ///
29 /// # Returns
30 ///
31 /// - `Self::OutputText` - The text data of the response.
32 fn text(&self) -> Self::OutputText {
33 self.clone()
34 }
35
36 /// Converts the text response to its binary representation.
37 ///
38 /// # Returns
39 ///
40 /// - `UdpResponseBinary` - The binary representation of the response.
41 fn binary(&self) -> UdpResponseBinary {
42 self.clone().into_bytes()
43 }
44}