1const ERROR_FIRST: u64 = 0x52e4a40fa8db;
5const ERROR_LAST: u64 = 0x52e5ac983162;
6
7pub const fn error_from_http3(code: u64) -> Option<u32> {
9 if code < ERROR_FIRST || code > ERROR_LAST {
10 return None;
11 }
12
13 let code = code - ERROR_FIRST;
14 let code = code - code / 0x1f;
15
16 Some(code as u32)
17}
18
19pub const fn error_to_http3(code: u32) -> u64 {
21 ERROR_FIRST + code as u64 + code as u64 / 0x1e
22}
23
24use thiserror::Error;
25
26pub type Result<T> = std::result::Result<T, Error>;
28
29#[derive(Debug, Error)]
31pub enum Error {
32 #[error("connection closed")]
34 Closed,
35
36 #[error("invalid url: {0}")]
38 InvalidUrl(String),
39
40 #[error("protocol error: {0}")]
42 Protocol(String),
43
44 #[error("io error: {0}")]
46 Io(String),
47
48 #[error("tls error: {0}")]
50 Tls(String),
51
52 #[error("unsupported: {0}")]
54 Unsupported(String),
55
56 #[error("session error: {0}")]
58 Session(String),
59
60 #[error("other error: {0}")]
62 Other(String),
63}
64
65impl Error {
66 pub fn other<E: std::fmt::Display>(e: E) -> Self {
68 Self::Other(e.to_string())
69 }
70}