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 #[inline]
21 fn from(response: &[u8]) -> Self::OutputText
22 where
23 Self: Sized,
24 {
25 <UdpResponseBinary as ResponseTrait>::from(response).text()
26 }
27
28 /// Returns the text representation of the response.
29 ///
30 /// # Returns
31 ///
32 /// - `Self::OutputText` - The text data of the response.
33 #[inline]
34 fn text(&self) -> Self::OutputText {
35 self.clone()
36 }
37
38 /// Converts the text response to its binary representation.
39 ///
40 /// # Returns
41 ///
42 /// - `UdpResponseBinary` - The binary representation of the response.
43 #[inline]
44 fn binary(&self) -> UdpResponseBinary {
45 self.clone().into_bytes()
46 }
47}