1pub type Result<T> = core::result::Result<T, NetError>;
10
11#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum NetError {
15 #[error(transparent)]
16 AddrParseError(#[from] core::net::AddrParseError),
17
18 #[error(transparent)]
19 CoreError(#[from] arachnid_core::Error),
20}
21
22#[cfg(feature = "alloc")]
23impl NetError {
24 pub fn box_error<E>(error: E) -> Self
25 where
26 E: core::error::Error + Send + Sync + 'static,
27 {
28 Self::CoreError(arachnid_core::Error::box_error(error))
29 }
30
31 pub fn unknown<E>(error: E) -> Self
32 where
33 E: alloc::string::ToString,
34 {
35 Self::CoreError(arachnid_core::Error::unknown(error))
36 }
37}
38
39#[cfg(feature = "alloc")]
40impl From<NetError> for arachnid_core::Error {
41 fn from(value: NetError) -> Self {
42 match value {
43 NetError::CoreError(e) => e,
44 _ => arachnid_core::Error::box_error(value),
45 }
46 }
47}
48
49#[cfg(feature = "alloc")]
50impl From<&str> for NetError {
51 fn from(value: &str) -> Self {
52 Self::CoreError(value.into())
53 }
54}
55
56#[cfg(feature = "alloc")]
57impl From<alloc::string::String> for NetError {
58 fn from(value: alloc::string::String) -> Self {
59 Self::CoreError(value.into())
60 }
61}