etherparse/transport/
tcp_option_write_error.rs1#[derive(Clone, Debug, Eq, PartialEq)]
3pub enum TcpOptionWriteError {
4 NotEnoughSpace(usize),
10}
11
12#[cfg(feature = "std")]
13#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
14impl std::error::Error for TcpOptionWriteError {
15 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
16 None
17 }
18}
19
20impl core::fmt::Display for TcpOptionWriteError {
21 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
22 use TcpOptionWriteError::*;
23 match self {
24 NotEnoughSpace(size) => {
25 write!(f, "TcpOptionWriteError: Not enough memory to store all options in the options section of a tcp header (maximum 40 bytes can be stored, the options would have needed {} bytes).", size)
26 }
27 }
28 }
29}
30
31#[cfg(test)]
32mod test {
33 use crate::*;
34 use alloc::format;
35 use proptest::prelude::*;
36
37 #[test]
38 fn debug() {
39 use TcpOptionWriteError::*;
40 assert_eq!("NotEnoughSpace(0)", format!("{:?}", NotEnoughSpace(0)));
41 }
42
43 #[test]
44 fn clone_eq() {
45 use TcpOptionWriteError::*;
46 let value = NotEnoughSpace(123);
47 assert_eq!(value, value.clone());
48 }
49
50 #[cfg(feature = "std")]
51 proptest! {
52 #[test]
53 fn source(arg_usize in any::<usize>()) {
54 use std::error::Error;
55 use crate::TcpOptionWriteError::*;
56
57 assert!(NotEnoughSpace(arg_usize).source().is_none());
58 }
59 }
60
61 proptest! {
62 #[test]
63 fn fmt(arg_usize in any::<usize>()) {
64 use crate::TcpOptionWriteError::*;
65
66 assert_eq!(
67 &format!("TcpOptionWriteError: Not enough memory to store all options in the options section of a tcp header (maximum 40 bytes can be stored, the options would have needed {} bytes).", arg_usize),
68 &format!("{}", NotEnoughSpace(arg_usize))
69 );
70 }
71 }
72}