psp_net/socket/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use core::fmt::Display;

use alloc::string::String;

/// An error that can occur with a socket
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum SocketError {
    /// Unsupported address family
    UnsupportedAddressFamily,
    /// Socket error with errno
    Errno(i32),
    /// Other error
    Other(String),
    /// Unknown error
    #[default]
    Unknown,
}

impl Display for SocketError {
    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
        write!(f, "{self:?}")
    }
}

impl embedded_io::Error for SocketError {
    fn kind(&self) -> embedded_io::ErrorKind {
        match self {
            SocketError::UnsupportedAddressFamily => embedded_io::ErrorKind::Unsupported,
            _ => embedded_io::ErrorKind::Other,
        }
    }
}

// re-exports
pub type TlsError = embedded_tls::TlsError;