arachnid_net/
error.rs

1/*
2    Appellation: error <module>
3    Created At: 2026.01.10:15:38:55
4    Contrib: @FL03
5*/
6//! this module defines the core error type for the crate
7
8/// a type alias for a [`Result`](core::result::Result) configured to use the custom [`Error`] type.
9pub type Result<T> = core::result::Result<T, NetError>;
10
11/// The custom error type for the crate.
12#[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}