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
use crate::preview2::bindings::wasi::sockets::network::ErrorCode;
use crate::preview2::{TableError, TrappableError};
use cap_std::net::Pool;

pub struct Network {
    pub pool: Pool,
    pub allow_ip_name_lookup: bool,
}

pub type SocketResult<T> = Result<T, SocketError>;

pub type SocketError = TrappableError<ErrorCode>;

impl From<TableError> for SocketError {
    fn from(error: TableError) -> Self {
        Self::trap(error)
    }
}

impl From<std::io::Error> for SocketError {
    fn from(error: std::io::Error) -> Self {
        ErrorCode::from(error).into()
    }
}

impl From<rustix::io::Errno> for SocketError {
    fn from(error: rustix::io::Errno) -> Self {
        ErrorCode::from(error).into()
    }
}