Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit fd59420

Browse files
committed
Merge pull request #33 from mletterle/rust-updates
Idiomatic changes to allow rust-http to build on latest rust compiler
2 parents db0deeb + e238d57 commit fd59420

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed

src/libhttp/codegen/branchify.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#[macro_escape];
22

33
use std::str::CharIterator;
4-
use std::rt::io::file::FileWriter;
54
use std::rt::io::Writer;
65

76
struct ParseBranch {
@@ -79,7 +78,7 @@ macro_rules! branchify(
7978
/// replaced with an expression (literal or non-literal) evaluating to a ``~str`` (it is
8079
/// ``{}`` only, not arbitrary format strings)
8180
pub fn generate_branchified_method(
82-
writer: &mut FileWriter,
81+
writer: &mut Writer,
8382
branches: &[ParseBranch],
8483
indent: uint,
8584
read_call: &str,
@@ -88,7 +87,7 @@ pub fn generate_branchified_method(
8887
valid: &str,
8988
unknown: &str) {
9089

91-
fn r(writer: &mut FileWriter, branch: &ParseBranch, prefix: &str, indent: uint, read_call: &str,
90+
fn r(writer: &mut Writer, branch: &ParseBranch, prefix: &str, indent: uint, read_call: &str,
9291
end: &str, max_len: &str, valid: &str, unknown: &str) {
9392
let indentstr = " ".repeat(indent * 4);
9493
let w = |s: &str| {

src/libhttp/codegen/codegen.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
#[feature(macro_rules)];
22

33
use std::rt::io::{Writer, CreateOrTruncate};
4-
use std::rt::io::file::{FileInfo, FileWriter};
4+
use std::rt::io::file::FileInfo;
55
use std::os;
66

77
pub mod branchify;
88
pub mod status;
99
pub mod read_method;
1010

11-
trait WriterExtensions {
12-
fn write_str(&mut self, msg: &str);
13-
}
14-
15-
impl<T: Writer> WriterExtensions for T {
16-
fn write_str(&mut self, msg: &str) {
17-
self.write(msg.as_bytes());
18-
}
19-
}
20-
2111
fn main() {
2212
let args = os::args();
2313
match args.len() {
@@ -46,11 +36,11 @@ fn main() {
4636
}
4737
}
4838

49-
pub fn get_writer(output_dir: &Path, filename: &str) -> FileWriter {
39+
pub fn get_writer(output_dir: &Path, filename: &str) -> ~Writer {
5040
let mut output_file = output_dir.clone();
5141
output_file.push(filename);
5242
match output_file.open_writer(CreateOrTruncate) {
53-
Some(writer) => writer,
43+
Some(writer) => ~writer as ~Writer,
5444
None => fail!("Unable to write file"),
5545
}
5646
}

src/libhttp/codegen/read_method.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::branchify::generate_branchified_method;
22
use super::get_writer;
3+
use std::rt::io::Writer;
34

45
pub fn generate(output_dir: &Path) {
56
let mut writer = get_writer(output_dir, "read_method.rs");
@@ -13,7 +14,7 @@ pub fn generate(output_dir: &Path) {
1314
"));
1415

1516
generate_branchified_method(
16-
&mut writer,
17+
writer,
1718
branchify!(case sensitive,
1819
"CONNECT" => Connect,
1920
"DELETE" => Delete,

src/libhttp/codegen/status.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::ascii::StrAsciiExt;
1111
use std::hashmap::HashSet;
1212
use std::either::{Either, Left, Right};
1313
use std::vec;
14+
use std::rt::io::Writer;
1415
use super::get_writer;
1516

1617
type HeadingOrStatus = Either<&'static str, Status>;
@@ -154,26 +155,26 @@ pub fn generate(output_dir: &Path) {
154155
Right(status) => status.reason.len(),
155156
}).max_by(|&i| i).unwrap();
156157
}
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.
158159
159160
use std::fmt;
160161
use std::ascii::StrAsciiExt;
161162
162163
/// HTTP status code
163164
#[deriving(Eq)]
164165
pub enum Status {
165-
");
166+
".as_bytes());
166167
for &entry in entries.iter() {
167168
match entry {
168-
Left(heading) => out.write_str(format!("\n // {}\n", heading)),
169+
Left(heading) => write!(out, "\n // {}\n", heading),
169170
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),
172173
},
173174
}
174175
}
175176

176-
out.write_str("
177+
out.write("
177178
UnregisteredStatus(u16, ~str),
178179
}
179180
@@ -182,31 +183,31 @@ impl Status {
182183
/// Get the status code
183184
pub fn code(&self) -> u16 {
184185
match *self {
185-
");
186+
".as_bytes());
186187
for &entry in entries.iter() {
187188
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),
191192
}
192193
}
193-
out.write_str("
194+
out.write("
194195
UnregisteredStatus(code, _) => code,
195196
}
196197
}
197198
198199
/// Get the reason phrase
199200
pub fn reason(&self) -> ~str {
200201
match *self {
201-
");
202+
".as_bytes());
202203
for &entry in entries.iter() {
203204
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)
207208
}
208209
}
209-
out.write_str("
210+
out.write("
210211
UnregisteredStatus(_, ref reason) => (*reason).clone(),
211212
}
212213
}
@@ -215,18 +216,18 @@ impl Status {
215216
pub fn from_code_and_reason(status: u16, reason: ~str) -> Status {
216217
let reason_lower = reason.to_ascii_lower();
217218
match (status, reason_lower.as_slice()) {
218-
");
219+
".as_bytes());
219220
for &entry in entries.iter() {
220221
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",
223224
status.code,
224225
status.reason.to_ascii_lower(),
225226
status.reason_padding_spaces(),
226-
status.ident())),
227+
status.ident()),
227228
}
228229
}
229-
out.write_str("
230+
out.write("
230231
(_, _) => UnregisteredStatus(status, reason),
231232
}
232233
}
@@ -287,24 +288,24 @@ impl FromPrimitive for Status {
287288
/// For example, `from_u64(200)` will return `OK`.
288289
fn from_u64(n: u64) -> Option<Status> {
289290
Some(match n {
290-
");
291+
".as_bytes());
291292
let mut matched_numbers = HashSet::new();
292293
for &entry in entries.iter() {
293294
match entry {
294-
Left(heading) => out.write_str(format!("\n // {}\n", heading)),
295+
Left(heading) => write!(out, "\n // {}\n", heading),
295296
Right(status) => {
296297
if !matched_numbers.contains(&status.code) {
297298
// Purpose: FailedDependency and MethodFailure both use 424,
298299
// 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());
300301
matched_numbers.insert(status.code);
301302
}
302303
},
303304
}
304305
}
305-
out.write_str("
306+
out.write("
306307
_ => { return None }
307308
})
308309
}
309-
}");
310+
}".as_bytes());
310311
}

0 commit comments

Comments
 (0)