@@ -11,6 +11,7 @@ use std::ascii::StrAsciiExt;
11
11
use std:: hashmap:: HashSet ;
12
12
use std:: either:: { Either , Left , Right } ;
13
13
use std:: vec;
14
+ use std:: rt:: io:: Writer ;
14
15
use super :: get_writer;
15
16
16
17
type HeadingOrStatus = Either < & ' static str , Status > ;
@@ -154,26 +155,26 @@ pub fn generate(output_dir: &Path) {
154
155
Right ( status) => status. reason . len ( ) ,
155
156
} ) . max_by ( |& i| i) . unwrap ( ) ;
156
157
}
157
- out. write_str ( "// This file is automatically generated file is used as http::status.
158
+ out. write ( "// This file is automatically generated file is used as http::status.
158
159
159
160
use std::fmt;
160
161
use std::ascii::StrAsciiExt;
161
162
162
163
/// HTTP status code
163
164
#[deriving(Eq)]
164
165
pub enum Status {
165
- " ) ;
166
+ " . as_bytes ( ) ) ;
166
167
for & entry in entries. iter ( ) {
167
168
match entry {
168
- Left ( heading) => out . write_str ( format ! ( "\n // {}\n " , heading) ) ,
169
+ Left ( heading) => write ! ( out , "\n // {}\n " , heading) ,
169
170
Right ( status) => match status. comment {
170
- None => out . write_str ( format ! ( " {},\n " , status. ident( ) ) ) ,
171
- Some ( comment) => out . write_str ( format ! ( " {}, // {}\n " , status. ident( ) , comment) ) ,
171
+ None => write ! ( out , " {},\n " , status. ident( ) ) ,
172
+ Some ( comment) => write ! ( out , " {}, // {}\n " , status. ident( ) , comment) ,
172
173
} ,
173
174
}
174
175
}
175
176
176
- out. write_str ( "
177
+ out. write ( "
177
178
UnregisteredStatus(u16, ~str),
178
179
}
179
180
@@ -182,31 +183,31 @@ impl Status {
182
183
/// Get the status code
183
184
pub fn code(&self) -> u16 {
184
185
match *self {
185
- " ) ;
186
+ " . as_bytes ( ) ) ;
186
187
for & entry in entries. iter ( ) {
187
188
match entry {
188
- Left ( heading) => out . write_str ( format ! ( "\n // {}\n " , heading) ) ,
189
- Right ( status) => out . write_str ( format ! ( " {} => {},\n " ,
190
- status. padded_ident( ) , status. code) ) ,
189
+ Left ( heading) => write ! ( out , "\n // {}\n " , heading) ,
190
+ Right ( status) => write ! ( out , " {} => {},\n " ,
191
+ status. padded_ident( ) , status. code) ,
191
192
}
192
193
}
193
- out. write_str ( "
194
+ out. write ( "
194
195
UnregisteredStatus(code, _) => code,
195
196
}
196
197
}
197
198
198
199
/// Get the reason phrase
199
200
pub fn reason(&self) -> ~str {
200
201
match *self {
201
- " ) ;
202
+ " . as_bytes ( ) ) ;
202
203
for & entry in entries. iter ( ) {
203
204
match entry {
204
- Left ( heading) => out . write_str ( format ! ( "\n // {}\n " , heading) ) ,
205
- Right ( status) => out . write_str ( format ! ( " {} => ~\" {}\" ,\n " ,
206
- status. padded_ident( ) , status. reason) )
205
+ Left ( heading) => write ! ( out , "\n // {}\n " , heading) ,
206
+ Right ( status) => write ! ( out , " {} => ~\" {}\" ,\n " ,
207
+ status. padded_ident( ) , status. reason)
207
208
}
208
209
}
209
- out. write_str ( "
210
+ out. write ( "
210
211
UnregisteredStatus(_, ref reason) => (*reason).clone(),
211
212
}
212
213
}
@@ -215,18 +216,18 @@ impl Status {
215
216
pub fn from_code_and_reason(status: u16, reason: ~str) -> Status {
216
217
let reason_lower = reason.to_ascii_lower();
217
218
match (status, reason_lower.as_slice()) {
218
- " ) ;
219
+ " . as_bytes ( ) ) ;
219
220
for & entry in entries. iter ( ) {
220
221
match entry {
221
- Left ( heading) => out . write_str ( format ! ( "\n // {}\n " , heading) ) ,
222
- Right ( status) => out . write_str ( format ! ( " ({}, \" {}\" ){} => {},\n " ,
222
+ Left ( heading) => write ! ( out , "\n // {}\n " , heading) ,
223
+ Right ( status) => write ! ( out , " ({}, \" {}\" ){} => {},\n " ,
223
224
status. code,
224
225
status. reason. to_ascii_lower( ) ,
225
226
status. reason_padding_spaces( ) ,
226
- status. ident( ) ) ) ,
227
+ status. ident( ) ) ,
227
228
}
228
229
}
229
- out. write_str ( "
230
+ out. write ( "
230
231
(_, _) => UnregisteredStatus(status, reason),
231
232
}
232
233
}
@@ -287,24 +288,24 @@ impl FromPrimitive for Status {
287
288
/// For example, `from_u64(200)` will return `OK`.
288
289
fn from_u64(n: u64) -> Option<Status> {
289
290
Some(match n {
290
- " ) ;
291
+ " . as_bytes ( ) ) ;
291
292
let mut matched_numbers = HashSet :: new ( ) ;
292
293
for & entry in entries. iter ( ) {
293
294
match entry {
294
- Left ( heading) => out . write_str ( format ! ( "\n // {}\n " , heading) ) ,
295
+ Left ( heading) => write ! ( out , "\n // {}\n " , heading) ,
295
296
Right ( status) => {
296
297
if !matched_numbers. contains ( & status. code ) {
297
298
// Purpose: FailedDependency and MethodFailure both use 424,
298
299
// but clearly they mustn't both go in here
299
- out . write_str ( format ! ( " {:u} => {},\n " , status. code, status. ident( ) ) ) ;
300
+ write ! ( out , " {:u} => {},\n " , status. code, status. ident( ) ) ;
300
301
matched_numbers. insert ( status. code ) ;
301
302
}
302
303
} ,
303
304
}
304
305
}
305
- out. write_str ( "
306
+ out. write ( "
306
307
_ => { return None }
307
308
})
308
309
}
309
- }" ) ;
310
+ }" . as_bytes ( ) ) ;
310
311
}
0 commit comments