Skip to content

Commit 6010b5f

Browse files
committed
Merge pull request chris-morgan#20 from mozilla-servo/rustup_20140515
Rust upgrade
2 parents 9a330d9 + f876247 commit 6010b5f

29 files changed

+446
-440
lines changed

Makefile.in

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
SSL_LIB ?= %SSL_LIB%
22
SSL_CFG ?= %SSL_CFG%
33
ifdef SSL_LIB
4-
SSL_CFG += -L "$(SSL_LIB)"
4+
SSL_CFG_AND_LIB=$(SSL_CFG) -L "$(SSL_LIB)"
5+
else
6+
SSL_CFG_AND_LIB=$(SSL_CFG)
57
endif
68
RUSTC ?= rustc
79
RUSTDOC ?= rustdoc
810
RUSTPKG ?= rustpkg
9-
RUSTFLAGS ?= -O $(SSL_CFG)
11+
RUSTFLAGS ?= -O $(SSL_CFG_AND_LIB)
1012
RUST_REPOSITORY ?= ../rust
1113
RUST_CTAGS ?= $(RUST_REPOSITORY)/src/etc/ctags.rust
1214
VERSION=0.1-pre
@@ -85,7 +87,7 @@ clean:
8587
rm -rf build/
8688
rm -rf bin/ .rust/
8789

88-
TAGS:
89-
ctags -f TAGS --options=$(RUST_CTAGS) -R src
90+
TAGS: $(http_files)
91+
ctags -f TAGS --options="$(RUST_CTAGS)" -R src/http
9092

9193
.PHONY: all http examples docs clean check quickcheck

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ In Rust, there is no base of code already following such a convention and so we
158158
are not tethered by this requirement. My own feeling on such matters is that
159159
for the static typing world having such things is not beneficial, anyway. Most
160160
web systems would have something along these lines, working with what is
161-
effectively a ``Map<~str, ~str>``::
161+
effectively a ``Map<StrBuf, StrBuf>``::
162162

163163
response.headers["Date"] = format_http_time(now_utc())
164164

@@ -170,7 +170,7 @@ thus?
170170
response.headers.date = now_utc()
171171

172172
To be certain, there may be need for unknown headers; yet even there one
173-
probably does not wish a ``~str`` value, but a more suitable type implementing
173+
probably does not wish a ``StrBuf`` value, but a more suitable type implementing
174174
a trait to convert to and from an appropriate string.
175175

176176
Note that with these examples the precise form is not determined.

src/codegen/branchify.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
#![macro_escape]
22

33
use std::str::Chars;
4+
use std::vec::Vec;
45
use std::io::IoResult;
56

7+
#[deriving(Clone)]
68
pub struct ParseBranch {
7-
matches: ~[u8],
8-
result: Option<~str>,
9-
children: ~[ParseBranch],
9+
matches: Vec<u8>,
10+
result: Option<StrBuf>,
11+
children: Vec<ParseBranch>,
1012
}
1113

1214
impl ParseBranch {
1315
fn new() -> ParseBranch {
1416
ParseBranch {
15-
matches: ~[],
17+
matches: Vec::new(),
1618
result: None,
17-
children: ~[],
19+
children: Vec::new()
1820
}
1921
}
2022
}
2123

22-
pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> ~[ParseBranch] {
24+
pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec<ParseBranch> {
2325
let mut root = ParseBranch::new();
2426

2527
fn go_down_moses(branch: &mut ParseBranch, mut chariter: Chars, result: &str, case_sensitive: bool) {
2628
match chariter.next() {
2729
Some(c) => {
2830
let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_upper().to_byte() };
2931
for next_branch in branch.children.mut_iter() {
30-
if next_branch.matches[0] == first_case {
32+
if *next_branch.matches.get(0) == first_case {
3133
go_down_moses(next_branch, chariter, result, case_sensitive);
3234
return;
3335
}
@@ -41,11 +43,12 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> ~[ParseBranc
4143
}
4244
}
4345
branch.children.push(subbranch);
44-
go_down_moses(&mut branch.children[branch.children.len() - 1], chariter, result, case_sensitive);
46+
let i = branch.children.len() - 1;
47+
go_down_moses(branch.children.get_mut(i), chariter, result, case_sensitive);
4548
},
4649
None => {
4750
assert!(branch.result.is_none());
48-
branch.result = Some(result.to_owned());
51+
branch.result = Some(StrBuf::from_str(result));
4952
},
5053
}
5154
};
@@ -62,7 +65,7 @@ macro_rules! branchify(
6265
::branchify::branchify([$(($key, stringify!($value))),*], true)
6366
);
6467
(case insensitive, $($key:expr => $value:ident),*) => (
65-
branchify([$(($key, stringify!($value))),*], false)
68+
::branchify::branchify([$(($key, stringify!($value))),*], false)
6669
);
6770
)
6871

@@ -75,11 +78,11 @@ macro_rules! branchify(
7578
/// :param max_len: the maximum length a value may be before giving up and returning ``None``
7679
/// :param valid: the function call to if a byte ``b`` is valid
7780
/// :param unknown: the expression to call for an unknown value; in this string, ``{}`` will be
78-
/// replaced with an expression (literal or non-literal) evaluating to a ``~str`` (it is
81+
/// replaced with an expression (literal or non-literal) evaluating to a ``StrBuf`` (it is
7982
/// ``{}`` only, not arbitrary format strings)
8083
pub fn generate_branchified_method(
8184
writer: &mut Writer,
82-
branches: &[ParseBranch],
85+
branches: Vec<ParseBranch>,
8386
indent: uint,
8487
read_call: &str,
8588
end: &str,
@@ -105,7 +108,7 @@ pub fn generate_branchified_method(
105108
Some(ref result) =>
106109
w!(format!(" Ok(b) if b == SP => return Ok({}),", *result)),
107110
None => w!(format!(" Ok(b) if b == SP => return Ok({}),",
108-
unknown.replace("{}", format!("~\"{}\"", next_prefix)))),
111+
unknown.replace("{}", format!("StrBuf::from_str(\"{}\")", next_prefix)))),
109112
}
110113
w!(format!(" Ok(b) if {} => (\"{}\", b),", valid, next_prefix));
111114
w!(" Ok(_) => return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"bad value\", detail: None }),");
@@ -130,7 +133,7 @@ pub fn generate_branchified_method(
130133
w!( (" Err(err) => return Err(err),"));
131134
w!( ("};"));
132135
w!( ("// OK, that didn't pan out. Let's read the rest and see what we get."));
133-
w!( ("let mut s = s.to_owned();"));
136+
w!( ("let mut s = StrBuf::from_str(s);"));
134137
w!( ("s.push_char(next_byte as char);"));
135138
w!( ("loop {"));
136139
w!(format!(" match {} \\{", read_call));

src/codegen/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ fn main() {
3737
}
3838
}
3939

40-
pub fn get_writer(output_dir: &Path, filename: &str) -> ~Writer {
40+
pub fn get_writer(output_dir: &Path, filename: &str) -> Box<Writer> {
4141
let mut output_file = output_dir.clone();
4242
output_file.push(filename);
4343
match File::open_mode(&output_file, Truncate, Write) {
44-
Ok(writer) => ~writer as ~Writer,
44+
Ok(writer) => box writer as Box<Writer>,
4545
Err(e) => fail!("Unable to write file: {}", e.desc),
4646
}
4747
}

src/codegen/status.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use collections::hashmap::HashSet;
1111
use std::ascii::StrAsciiExt;
12-
use std::slice;
1312
use std::io::IoResult;
1413
use super::get_writer;
1514

@@ -35,12 +34,14 @@ fn StatusN(code: uint, reason: &'static str) -> HeadingOrStatus {
3534
}
3635

3736
impl Status {
38-
fn ident(&self) -> ~str {
37+
fn ident(&self) -> StrBuf {
3938
camel_case(self.reason)
4039
}
4140

42-
fn padded_ident(&self) -> ~str {
43-
self.ident() + " ".repeat(unsafe { longest_ident } - self.ident().len())
41+
fn padded_ident(&self) -> StrBuf {
42+
let mut result = self.ident();
43+
result.push_str(self.reason_padding_spaces());
44+
result
4445
}
4546

4647
fn reason_padding_spaces(&self) -> ~str {
@@ -50,22 +51,22 @@ impl Status {
5051

5152
/// >>> camel_case("I'm a Tea-pot")
5253
/// "ImATeaPot"
53-
fn camel_case(msg: &str) -> ~str {
54+
fn camel_case(msg: &str) -> StrBuf {
5455
let msg = msg.replace("-", " ").replace("'", "");
55-
let mut result: ~[Ascii] = slice::with_capacity(msg.len());
56+
let mut result = StrBuf::with_capacity(msg.len());
5657
let mut capitalise = true;
5758
for c in msg.chars() {
5859
let c = match capitalise {
59-
true => c.to_ascii().to_upper(),
60-
false => c.to_ascii().to_lower(),
60+
true => c.to_ascii().to_upper().to_char(),
61+
false => c.to_ascii().to_lower().to_char(),
6162
};
6263
// For a space, capitalise the next char
63-
capitalise = c.to_byte() == (' ' as u8);
64+
capitalise = c == ' ';
6465
if !capitalise { // And also, for a space, don't keep it
65-
result.push(c);
66+
result.push_char(c);
6667
}
6768
}
68-
result.into_str()
69+
result
6970
}
7071

7172
static mut longest_ident: uint = 0;
@@ -177,7 +178,7 @@ pub enum Status {
177178
}
178179

179180
try!(out.write("
180-
UnregisteredStatus(u16, ~str),
181+
UnregisteredStatus(u16, StrBuf),
181182
}
182183
183184
impl Status {
@@ -199,13 +200,13 @@ impl Status {
199200
}
200201
201202
/// Get the reason phrase
202-
pub fn reason(&self) -> ~str {
203+
pub fn reason(&self) -> StrBuf {
203204
match *self {
204205
".as_bytes()));
205206
for &entry in entries.iter() {
206207
match entry {
207208
Heading(heading) => try!(write!(out, "\n // {}\n", heading)),
208-
Status(status) => try!(write!(out, " {} => ~\"{}\",\n",
209+
Status(status) => try!(write!(out, " {} => StrBuf::from_str(\"{}\"),\n",
209210
status.padded_ident(), status.reason))
210211
}
211212
}
@@ -215,8 +216,8 @@ impl Status {
215216
}
216217
217218
/// Get a status from the code and reason
218-
pub fn from_code_and_reason(status: u16, reason: ~str) -> Status {
219-
let reason_lower = reason.to_ascii_lower();
219+
pub fn from_code_and_reason(status: u16, reason: StrBuf) -> Status {
220+
let reason_lower = reason.as_slice().to_ascii_lower();
220221
match (status, reason_lower.as_slice()) {
221222
".as_bytes()));
222223
for &entry in entries.iter() {

src/examples/client/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
};
2222
}
2323

24-
fn make_and_print_request(url: ~str) {
24+
fn make_and_print_request(url: &str) {
2525
let request: RequestWriter = RequestWriter::new(Get, from_str(url).expect("Invalid URL :-("))
2626
.unwrap();
2727

src/examples/server/apache_fake/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl Server for ApacheFakeServer {
2323

2424
fn handle_request(&self, _r: &Request, w: &mut ResponseWriter) {
2525
w.headers.date = Some(time::now_utc());
26-
w.headers.server = Some(~"Apache/2.2.22 (Ubuntu)");
27-
//w.headers.last_modified = Some(~"Thu, 05 May 2011 11:46:42 GMT");
26+
w.headers.server = Some(StrBuf::from_str("Apache/2.2.22 (Ubuntu)"));
27+
//w.headers.last_modified = Some(StrBuf::from_str("Thu, 05 May 2011 11:46:42 GMT"));
2828
w.headers.last_modified = Some(time::Tm {
2929
tm_sec: 42, // seconds after the minute ~[0-60]
3030
tm_min: 46, // minutes after the hour ~[0-59]
@@ -36,22 +36,22 @@ impl Server for ApacheFakeServer {
3636
tm_yday: 0, // days since January 1 ~[0-365]
3737
tm_isdst: 0, // Daylight Savings Time flag
3838
tm_gmtoff: 0, // offset from UTC in seconds
39-
tm_zone: ~"GMT", // timezone abbreviation
39+
tm_zone: "GMT".to_owned(), // timezone abbreviation
4040
tm_nsec: 0, // nanoseconds
4141
});
4242
w.headers.etag = Some(headers::etag::EntityTag {
4343
weak: false,
44-
opaque_tag: ~"501b29-b1-4a285ed47404a" });
44+
opaque_tag: StrBuf::from_str("501b29-b1-4a285ed47404a") });
4545
w.headers.accept_ranges = Some(headers::accept_ranges::RangeUnits(
4646
vec!(headers::accept_ranges::Bytes)));
4747
w.headers.content_length = Some(177);
48-
w.headers.vary = Some(~"Accept-Encoding");
48+
w.headers.vary = Some(StrBuf::from_str("Accept-Encoding"));
4949
w.headers.content_type = Some(headers::content_type::MediaType {
50-
type_: ~"text",
51-
subtype: ~"html",
50+
type_: StrBuf::from_str("text"),
51+
subtype: StrBuf::from_str("html"),
5252
parameters: Vec::new()
5353
});
54-
w.headers.extensions.insert(~"X-Pad", ~"avoid browser bug");
54+
w.headers.extensions.insert(StrBuf::from_str("X-Pad"), StrBuf::from_str("avoid browser bug"));
5555

5656
w.write(bytes!("\
5757
<html><body><h1>It works!</h1>\n\

src/examples/server/hello_world/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ impl Server for HelloWorldServer {
2323
w.headers.date = Some(time::now_utc());
2424
w.headers.content_length = Some(14);
2525
w.headers.content_type = Some(MediaType {
26-
type_: ~"text",
27-
subtype: ~"plain",
28-
parameters: vec!((~"charset", ~"UTF-8"))
26+
type_: StrBuf::from_str("text"),
27+
subtype: StrBuf::from_str("plain"),
28+
parameters: vec!((StrBuf::from_str("charset"), StrBuf::from_str("UTF-8")))
2929
});
30-
w.headers.server = Some(~"Example");
30+
w.headers.server = Some(StrBuf::from_str("Example"));
3131

3232
w.write(bytes!("Hello, World!\n")).unwrap();
3333
}

src/examples/server/info/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ impl Server for InfoServer {
2424
fn handle_request(&self, r: &Request, w: &mut ResponseWriter) {
2525
w.headers.date = Some(time::now_utc());
2626
w.headers.content_type = Some(MediaType {
27-
type_: ~"text",
28-
subtype: ~"html",
29-
parameters: vec!((~"charset", ~"UTF-8"))
27+
type_: StrBuf::from_str("text"),
28+
subtype: StrBuf::from_str("html"),
29+
parameters: vec!((StrBuf::from_str("charset"), StrBuf::from_str("UTF-8")))
3030
});
31-
w.headers.server = Some(~"Rust Thingummy/0.0-pre");
31+
w.headers.server = Some(StrBuf::from_str("Rust Thingummy/0.0-pre"));
3232
w.write(bytes!("<!DOCTYPE html><title>Rust HTTP server</title>")).unwrap();
3333

3434
w.write(bytes!("<h1>Request</h1>")).unwrap();

src/examples/server/request_uri/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Server for RequestUriServer {
2828

2929
fn handle_request(&self, r: &Request, w: &mut ResponseWriter) {
3030
w.headers.date = Some(time::now_utc());
31-
w.headers.server = Some(~"Rust Thingummy/0.1-pre");
31+
w.headers.server = Some(StrBuf::from_str("Rust Thingummy/0.1-pre"));
3232

3333
match (&r.method, &r.request_uri) {
3434
(&Connect, _) => {
@@ -59,8 +59,8 @@ impl Server for RequestUriServer {
5959
}
6060

6161
w.headers.content_type = Some(MediaType {
62-
type_: ~"text",
63-
subtype: ~"html",
62+
type_: StrBuf::from_str("text"),
63+
subtype: StrBuf::from_str("html"),
6464
parameters: Vec::new()
6565
});
6666

@@ -72,11 +72,11 @@ impl Server for RequestUriServer {
7272
// Actually, valid for the CONNECT method.
7373
},
7474
AbsoluteUri(ref url) => {
75-
println!("absoluteURI, {}", url.to_str());
75+
println!("absoluteURI, {}", url);
7676
//path =
7777
},
7878
AbsolutePath(ref url) => {
79-
println!("absolute path, {}", url.to_owned());
79+
println!("absolute path, {}", url);
8080
//w.status = a
8181
},
8282
}

0 commit comments

Comments
 (0)