9
9
10
10
use std:: ascii:: StrAsciiExt ;
11
11
use std:: hashmap:: HashSet ;
12
- use std:: either:: { Either , Left , Right } ;
13
12
use std:: vec;
14
13
use std:: io:: Writer ;
15
14
use super :: get_writer;
16
15
17
- type HeadingOrStatus = Either < & ' static str , Status > ;
16
+ enum HeadingOrStatus {
17
+ Heading ( & ' static str ) ,
18
+ Status ( Status ) ,
19
+ }
18
20
19
21
struct Status {
20
22
code : uint ,
@@ -24,12 +26,12 @@ struct Status {
24
26
25
27
/// Status with comment
26
28
fn StatusC ( code : uint , reason : & ' static str , comment : & ' static str ) -> HeadingOrStatus {
27
- Right ( Status { code : code, reason : reason, comment : Some ( comment) } )
29
+ Status ( Status { code : code, reason : reason, comment : Some ( comment) } )
28
30
}
29
31
30
32
/// Status without comment
31
33
fn StatusN ( code : uint , reason : & ' static str ) -> HeadingOrStatus {
32
- Right ( Status { code : code, reason : reason, comment : None } )
34
+ Status ( Status { code : code, reason : reason, comment : None } )
33
35
}
34
36
35
37
impl Status {
@@ -72,12 +74,12 @@ static mut longest_reason: uint = 0;
72
74
pub fn generate ( output_dir : & Path ) {
73
75
let mut out = get_writer ( output_dir, "status.rs" ) ;
74
76
let entries = [
75
- Left ( "1xx Informational" ) ,
77
+ Heading ( "1xx Informational" ) ,
76
78
StatusN ( 100 , "Continue" ) ,
77
79
StatusN ( 101 , "Switching Protocols" ) ,
78
80
StatusC ( 102 , "Processing" , "WebDAV; RFC 2518" ) ,
79
81
80
- Left ( "2xx Success" ) ,
82
+ Heading ( "2xx Success" ) ,
81
83
StatusN ( 200 , "OK" ) ,
82
84
StatusN ( 201 , "Created" ) ,
83
85
StatusN ( 202 , "Accepted" ) ,
@@ -89,7 +91,7 @@ pub fn generate(output_dir: &Path) {
89
91
StatusC ( 208 , "Already Reported" , "WebDAV; RFC 5842" ) ,
90
92
StatusC ( 226 , "IM Used" , "RFC 3229" ) ,
91
93
92
- Left ( "3xx Redirection" ) ,
94
+ Heading ( "3xx Redirection" ) ,
93
95
StatusN ( 300 , "Multiple Choices" ) ,
94
96
StatusN ( 301 , "Moved Permanently" ) ,
95
97
StatusN ( 302 , "Found" ) ,
@@ -100,7 +102,7 @@ pub fn generate(output_dir: &Path) {
100
102
StatusC ( 307 , "Temporary Redirect" , "since HTTP/1.1" ) ,
101
103
StatusC ( 308 , "Permanent Redirect" , "approved as experimental RFC: http://tools.ietf.org/html/draft-reschke-http-status-308" ) ,
102
104
103
- Left ( "4xx Client Error" ) ,
105
+ Heading ( "4xx Client Error" ) ,
104
106
StatusN ( 400 , "Bad Request" ) ,
105
107
StatusN ( 401 , "Unauthorized" ) ,
106
108
StatusN ( 402 , "Payment Required" ) ,
@@ -132,7 +134,7 @@ pub fn generate(output_dir: &Path) {
132
134
StatusC ( 431 , "Request Header Fields Too Large" , "RFC 6585" ) ,
133
135
StatusC ( 451 , "Unavailable For Legal Reasons" , "Internet draft" ) ,
134
136
135
- Left ( "5xx Server Error" ) ,
137
+ Heading ( "5xx Server Error" ) ,
136
138
StatusN ( 500 , "Internal Server Error" ) ,
137
139
StatusN ( 501 , "Not Implemented" ) ,
138
140
StatusN ( 502 , "Bad Gateway" ) ,
@@ -147,12 +149,12 @@ pub fn generate(output_dir: &Path) {
147
149
] ;
148
150
unsafe {
149
151
longest_ident = entries. iter ( ) . map ( |& e| match e {
150
- Left ( _heading) => 0 ,
151
- Right ( status) => status. ident ( ) . len ( ) ,
152
+ Heading ( _heading) => 0 ,
153
+ Status ( status) => status. ident ( ) . len ( ) ,
152
154
} ) . max_by ( |& i| i) . unwrap ( ) ;
153
155
longest_reason = entries. iter ( ) . map ( |& e| match e {
154
- Left ( _heading) => 0 ,
155
- Right ( status) => status. reason . len ( ) ,
156
+ Heading ( _heading) => 0 ,
157
+ Status ( status) => status. reason . len ( ) ,
156
158
} ) . max_by ( |& i| i) . unwrap ( ) ;
157
159
}
158
160
out. write ( "// This file is automatically generated file is used as http::status.
@@ -166,8 +168,8 @@ pub enum Status {
166
168
" . as_bytes ( ) ) ;
167
169
for & entry in entries. iter ( ) {
168
170
match entry {
169
- Left ( heading) => write ! ( out, "\n // {}\n " , heading) ,
170
- Right ( status) => match status. comment {
171
+ Heading ( heading) => write ! ( out, "\n // {}\n " , heading) ,
172
+ Status ( status) => match status. comment {
171
173
None => write ! ( out, " {},\n " , status. ident( ) ) ,
172
174
Some ( comment) => write ! ( out, " {}, // {}\n " , status. ident( ) , comment) ,
173
175
} ,
@@ -186,8 +188,8 @@ impl Status {
186
188
" . as_bytes ( ) ) ;
187
189
for & entry in entries. iter ( ) {
188
190
match entry {
189
- Left ( heading) => write ! ( out, "\n // {}\n " , heading) ,
190
- Right ( status) => write ! ( out, " {} => {},\n " ,
191
+ Heading ( heading) => write ! ( out, "\n // {}\n " , heading) ,
192
+ Status ( status) => write ! ( out, " {} => {},\n " ,
191
193
status. padded_ident( ) , status. code) ,
192
194
}
193
195
}
@@ -202,8 +204,8 @@ impl Status {
202
204
" . as_bytes ( ) ) ;
203
205
for & entry in entries. iter ( ) {
204
206
match entry {
205
- Left ( heading) => write ! ( out, "\n // {}\n " , heading) ,
206
- Right ( status) => write ! ( out, " {} => ~\" {}\" ,\n " ,
207
+ Heading ( heading) => write ! ( out, "\n // {}\n " , heading) ,
208
+ Status ( status) => write ! ( out, " {} => ~\" {}\" ,\n " ,
207
209
status. padded_ident( ) , status. reason)
208
210
}
209
211
}
@@ -219,8 +221,8 @@ impl Status {
219
221
" . as_bytes ( ) ) ;
220
222
for & entry in entries. iter ( ) {
221
223
match entry {
222
- Left ( heading) => write ! ( out, "\n // {}\n " , heading) ,
223
- Right ( status) => write ! ( out, " ({}, \" {}\" ){} => {},\n " ,
224
+ Heading ( heading) => write ! ( out, "\n // {}\n " , heading) ,
225
+ Status ( status) => write ! ( out, " ({}, \" {}\" ){} => {},\n " ,
224
226
status. code,
225
227
status. reason. to_ascii_lower( ) ,
226
228
status. reason_padding_spaces( ) ,
@@ -292,8 +294,8 @@ impl FromPrimitive for Status {
292
294
let mut matched_numbers = HashSet :: new ( ) ;
293
295
for & entry in entries. iter ( ) {
294
296
match entry {
295
- Left ( heading) => write ! ( out, "\n // {}\n " , heading) ,
296
- Right ( status) => {
297
+ Heading ( heading) => write ! ( out, "\n // {}\n " , heading) ,
298
+ Status ( status) => {
297
299
if !matched_numbers. contains ( & status. code ) {
298
300
// Purpose: FailedDependency and MethodFailure both use 424,
299
301
// but clearly they mustn't both go in here
0 commit comments