miltr_common/actions/
quit.rs1use bytes::BytesMut;
2
3use crate::decoding::Parsable;
4use crate::encoding::Writable;
5use crate::ProtocolError;
6
7#[derive(Clone, PartialEq, Debug, Default)]
9pub struct Quit;
10
11impl Quit {
12 const CODE: u8 = b'Q';
13}
14
15impl Parsable for Quit {
16 const CODE: u8 = Self::CODE;
17
18 fn parse(_buffer: BytesMut) -> Result<Self, ProtocolError> {
19 Ok(Self)
20 }
21}
22
23impl Writable for Quit {
24 fn write(&self, _buffer: &mut BytesMut) {}
25
26 fn len(&self) -> usize {
27 0
28 }
29
30 fn code(&self) -> u8 {
31 Self::CODE
32 }
33
34 fn is_empty(&self) -> bool {
35 false
36 }
37}
38
39#[derive(Clone, PartialEq, Debug, Default)]
41pub struct QuitNc;
42
43impl QuitNc {
44 const CODE: u8 = b'K';
45}
46
47impl Parsable for QuitNc {
48 const CODE: u8 = Self::CODE;
49
50 fn parse(_buffer: BytesMut) -> Result<Self, ProtocolError> {
51 Ok(Self)
52 }
53}
54
55impl Writable for QuitNc {
56 fn write(&self, _buffer: &mut BytesMut) {}
57
58 fn len(&self) -> usize {
59 0
60 }
61
62 fn code(&self) -> u8 {
63 Self::CODE
64 }
65
66 fn is_empty(&self) -> bool {
67 false
68 }
69}
70
71#[cfg(all(test, feature = "count-allocations"))]
72mod test {
73 use bytes::BytesMut;
74
75 use crate::decoding::Parsable;
76
77 #[test]
78 fn test_parse_quit() {
79 use super::Quit;
80
81 let buffer = BytesMut::from("this is quit buffer...");
82 let info = allocation_counter::measure(|| {
83 let _ = Quit::parse(buffer);
84 });
85 assert_eq!(info.count_total, 0);
87 }
88}