async_niri_socket/
error.rs

1use std::io;
2
3pub enum NiriReplyError {
4    /// Fail to communicate with Niri because of IO error.
5    IO(io::Error),
6    /// Some error message from Niri.
7    Niri(String),
8}
9
10impl NiriReplyError {
11    /// Return the IO error if there is any.
12    pub fn io_error(self) -> Option<io::Error> {
13        if let NiriReplyError::IO(err) = self {
14            Some(err)
15        } else {
16            None
17        }
18    }
19
20    /// Return the Niri error message if there is any.
21    pub fn niri_error_msg(self) -> Option<String> {
22        if let NiriReplyError::Niri(msg) = self {
23            Some(msg)
24        } else {
25            None
26        }
27    }
28}
29
30impl From<io::Error> for NiriReplyError {
31    fn from(value: io::Error) -> Self {
32        NiriReplyError::IO(value)
33    }
34}