dstar_gateway_core/error/
io_operation.rs

1//! `IoOperation` discriminator for I/O failures.
2
3/// What kind of I/O operation an [`crate::error::Error::Io`] variant
4/// was attempting when it failed.
5///
6/// Lets consumers distinguish "couldn't connect to auth server" from
7/// "lost connection to reflector" without parsing the error string.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9#[non_exhaustive]
10pub enum IoOperation {
11    /// Binding a UDP socket.
12    UdpBind,
13    /// Sending a UDP datagram.
14    UdpSend,
15    /// Receiving a UDP datagram.
16    UdpRecv,
17    /// Connecting the `DPlus` auth TCP stream.
18    TcpAuthConnect,
19    /// Writing to the `DPlus` auth TCP stream.
20    TcpAuthWrite,
21    /// Reading from the `DPlus` auth TCP stream.
22    TcpAuthRead,
23    /// HTTP GET for the host file fetcher.
24    HostsFetcherHttpGet,
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn io_operation_is_copy() {
33        let a = IoOperation::UdpRecv;
34        let b = a;
35        assert_eq!(a, b);
36    }
37
38    #[test]
39    fn io_operation_pattern_matches() {
40        let op = IoOperation::TcpAuthConnect;
41        assert!(
42            matches!(op, IoOperation::TcpAuthConnect),
43            "expected TcpAuthConnect, got {op:?}"
44        );
45    }
46}