Skip to main content

better_url/errors/
mod.rs

1//! Error types.
2
3mod generic;
4mod url;
5mod scheme;
6mod userinfo;
7mod host;
8mod host_port;
9mod port;
10mod path;
11mod query;
12mod fragment;
13
14pub use generic::*;
15pub use url::*;
16pub use scheme::*;
17pub use userinfo::*;
18pub use host::*;
19pub use host_port::*;
20pub use port::*;
21pub use path::*;
22pub use query::*;
23pub use fragment::*;
24
25/// Implement [`From`] of [`std::convert::Infallible`].
26macro_rules! from_infallible {
27    ($($t:ty),*) => {
28        $(
29            impl From<std::convert::Infallible> for $t {
30                fn from(value: std::convert::Infallible) -> Self {
31                    match value {}
32                }
33            }
34        )*
35    }
36}
37
38from_infallible!(
39    InvalidScheme, SetSchemeError,
40    SetUsernameError,
41    SetPasswordError,
42    InvalidHost, SetHostError,
43    InvalidDomainSegment, InvalidDomainSegments, SetDomainError,
44    InvalidPort, SetPortError,
45    SetPathError,
46    SetQueryError,
47    SetFragmentError
48);
49
50#[cfg(test)]
51mod tests {
52    use crate::prelude::*;
53
54
55    macro_rules! assert_size_1 {
56        ($($t:ty),*) => {
57            $(assert_eq!(std::mem::size_of::<$t>(), 1, "{}", stringify!($t));)*
58        }
59    }
60
61    #[test]
62    fn sizes() {
63        assert_size_1!(
64            SetDomainError,
65            SetSchemeError,
66            SetUserinfoError, SetUsernameError, SetPasswordError,
67            SetHostError,
68            SetPathError,
69            SetQueryError
70        );
71    }
72}