馃 The Definitive Gemini Protocol Toolkit
gemini
gemini-protocol
gemtext
parser
zero-dependency
toolkit
ast
converter
html
markdown
cli
networking
1use std::{fmt, fmt::Formatter};
2
3/// Simple Gemini status reporting
4///
5/// # Examples
6///
7/// ```rust
8/// use germ::request::Status;
9///
10/// assert_eq!(Status::from(10), Status::Input);
11/// assert_eq!(i32::from(Status::Input), 10);
12/// ```
13#[derive(Debug, Copy, Clone, PartialEq, Eq)]
14pub enum Status {
15 Input,
16 SensitiveInput,
17 Success,
18 TemporaryRedirect,
19 PermanentRedirect,
20 TemporaryFailure,
21 ServerUnavailable,
22 CGIError,
23 ProxyError,
24 SlowDown,
25 PermanentFailure,
26 NotFound,
27 Gone,
28 ProxyRefused,
29 BadRequest,
30 ClientCertificateRequired,
31 CertificateNotAuthorised,
32 CertificateNotValid,
33 Unsupported,
34}
35
36impl Default for Status {
37 fn default() -> Self { Self::Success }
38}
39
40impl From<Status> for i32 {
41 fn from(n: Status) -> Self {
42 match n {
43 Status::Input => 10,
44 Status::SensitiveInput => 11,
45 Status::Success => 20,
46 Status::TemporaryRedirect => 30,
47 Status::PermanentRedirect => 31,
48 Status::TemporaryFailure => 40,
49 Status::ServerUnavailable => 41,
50 Status::CGIError => 42,
51 Status::ProxyError => 43,
52 Status::SlowDown => 44,
53 Status::PermanentFailure => 50,
54 Status::NotFound => 51,
55 Status::Gone => 52,
56 Status::ProxyRefused => 53,
57 Status::BadRequest => 59,
58 Status::ClientCertificateRequired => 60,
59 Status::CertificateNotAuthorised => 61,
60 Status::CertificateNotValid => 62,
61 Status::Unsupported => 0,
62 }
63 }
64}
65
66impl From<i32> for Status {
67 fn from(n: i32) -> Self {
68 match n {
69 10 => Self::Input,
70 11 => Self::SensitiveInput,
71 20 => Self::Success,
72 30 => Self::TemporaryRedirect,
73 31 => Self::PermanentRedirect,
74 40 => Self::TemporaryFailure,
75 41 => Self::ServerUnavailable,
76 42 => Self::CGIError,
77 43 => Self::ProxyError,
78 44 => Self::SlowDown,
79 50 => Self::PermanentFailure,
80 51 => Self::NotFound,
81 52 => Self::Gone,
82 53 => Self::ProxyRefused,
83 59 => Self::BadRequest,
84 60 => Self::ClientCertificateRequired,
85 61 => Self::CertificateNotAuthorised,
86 62 => Self::CertificateNotValid,
87 _ => Self::Unsupported,
88 }
89 }
90}
91
92impl fmt::Display for Status {
93 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{self:?}") }
94}