vortex_protocol/tlv/
close.rs

1/*
2 *     Copyright 2025 The Dragonfly Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::error::Result;
18
19/// Close represents a close message.
20#[derive(Debug, Clone)]
21pub struct Close();
22
23/// Close implements the Close functions.
24impl Close {
25    /// new creates a new close.
26    pub fn new() -> Result<Self> {
27        Ok(Close())
28    }
29
30    /// len returns zero, because close message is empty.
31    pub fn len(&self) -> usize {
32        0
33    }
34
35    /// is_empty returns true, because close message is empty.
36    pub fn is_empty(&self) -> bool {
37        true
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_new() {
47        let result = Close::new();
48
49        assert!(result.is_ok());
50        assert_eq!(result.unwrap().len(), 0);
51    }
52
53    #[test]
54    fn test_is_empty() {
55        let result = Close::new();
56
57        assert!(result.is_ok());
58        assert!(result.unwrap().is_empty());
59    }
60}