Skip to content

Commit a02cf0c

Browse files
committed
Merge pull request chris-morgan#21 from mozilla-servo/rustup-20140528
Upgrade Rust
2 parents 6010b5f + e44576e commit a02cf0c

29 files changed

+371
-383
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ env:
22
global:
33
- secure: SkhFtAUkRRrDYHr6z6YhWtGouw6jsys7dBKLojA+M3M68EM9U1VG9oNHMasCdFUt0a+TdPte9JccufbhvZABnlo7+yU6hQ94jhsyQ9qSL5y7V+2eyWBkQZDqyFt3jgLyrrSV2Nkk22xI4UAm2iGRKel6lXWi7i0i9hDT+3W0dK4=
44
before_install:
5-
- yes | sudo add-apt-repository ppa:hansjorg/rust
6-
- sudo apt-get update
5+
- wget http://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz
6+
- tar xf rust-nightly-x86_64-unknown-linux-gnu.tar.gz
77
install:
8-
- sudo apt-get install rust-nightly
8+
- sudo ./rust-nightly-x86_64-unknown-linux-gnu/install.sh
99
- git clone https://github.com/sfackler/rust-openssl.git
1010
- cd rust-openssl
1111
- ./configure

README.rst

+2-2
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<StrBuf, StrBuf>``::
161+
effectively a ``Map<String, String>``::
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 ``StrBuf`` value, but a more suitable type implementing
173+
probably does not wish a ``String`` 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

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::IoResult;
77
#[deriving(Clone)]
88
pub struct ParseBranch {
99
matches: Vec<u8>,
10-
result: Option<StrBuf>,
10+
result: Option<String>,
1111
children: Vec<ParseBranch>,
1212
}
1313

@@ -27,7 +27,7 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec<ParseBra
2727
fn go_down_moses(branch: &mut ParseBranch, mut chariter: Chars, result: &str, case_sensitive: bool) {
2828
match chariter.next() {
2929
Some(c) => {
30-
let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_upper().to_byte() };
30+
let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_uppercase().to_byte() };
3131
for next_branch in branch.children.mut_iter() {
3232
if *next_branch.matches.get(0) == first_case {
3333
go_down_moses(next_branch, chariter, result, case_sensitive);
@@ -37,7 +37,7 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec<ParseBra
3737
let mut subbranch = ParseBranch::new();
3838
subbranch.matches.push(first_case);
3939
if !case_sensitive {
40-
let second_case = c.to_ascii().to_lower().to_byte();
40+
let second_case = c.to_ascii().to_lowercase().to_byte();
4141
if first_case != second_case {
4242
subbranch.matches.push(second_case);
4343
}
@@ -48,7 +48,7 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec<ParseBra
4848
},
4949
None => {
5050
assert!(branch.result.is_none());
51-
branch.result = Some(StrBuf::from_str(result));
51+
branch.result = Some(String::from_str(result));
5252
},
5353
}
5454
};
@@ -78,7 +78,7 @@ macro_rules! branchify(
7878
/// :param max_len: the maximum length a value may be before giving up and returning ``None``
7979
/// :param valid: the function call to if a byte ``b`` is valid
8080
/// :param unknown: the expression to call for an unknown value; in this string, ``{}`` will be
81-
/// replaced with an expression (literal or non-literal) evaluating to a ``StrBuf`` (it is
81+
/// replaced with an expression (literal or non-literal) evaluating to a ``String`` (it is
8282
/// ``{}`` only, not arbitrary format strings)
8383
pub fn generate_branchified_method(
8484
writer: &mut Writer,
@@ -102,13 +102,13 @@ pub fn generate_branchified_method(
102102
let next_prefix = format!("{}{}", prefix, c as char);
103103
w!(format!("Ok(b) if b == '{}' as u8 => match {} \\{", c as char, read_call));
104104
for b in branch.children.iter() {
105-
try!(r(writer, b, next_prefix, indent + 1, read_call, end, max_len, valid, unknown));
105+
try!(r(writer, b, next_prefix.as_slice(), indent + 1, read_call, end, max_len, valid, unknown));
106106
}
107107
match branch.result {
108108
Some(ref result) =>
109109
w!(format!(" Ok(b) if b == SP => return Ok({}),", *result)),
110110
None => w!(format!(" Ok(b) if b == SP => return Ok({}),",
111-
unknown.replace("{}", format!("StrBuf::from_str(\"{}\")", next_prefix)))),
111+
unknown.replace("{}", format!("String::from_str(\"{}\")", next_prefix).as_slice()))),
112112
}
113113
w!(format!(" Ok(b) if {} => (\"{}\", b),", valid, next_prefix));
114114
w!(" Ok(_) => return Err(::std::io::IoError { kind: ::std::io::OtherIoError, desc: \"bad value\", detail: None }),");
@@ -133,7 +133,7 @@ pub fn generate_branchified_method(
133133
w!( (" Err(err) => return Err(err),"));
134134
w!( ("};"));
135135
w!( ("// OK, that didn't pan out. Let's read the rest and see what we get."));
136-
w!( ("let mut s = StrBuf::from_str(s);"));
136+
w!( ("let mut s = String::from_str(s);"));
137137
w!( ("s.push_char(next_byte as char);"));
138138
w!( ("loop {"));
139139
w!(format!(" match {} \\{", read_call));

src/codegen/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ fn main() {
1919
os::set_exit_status(1);
2020
},
2121
3 => {
22-
let output_dir = Path::new(args[2].as_slice());
22+
let output_dir = Path::new(args.get(2).as_slice());
2323

24-
match args[1].as_slice() {
24+
match args.get(1).as_slice() {
2525
"read_method.rs" => read_method::generate(&output_dir).unwrap(),
2626
"status.rs" => status::generate(&output_dir).unwrap(),
2727
s => {
@@ -31,7 +31,7 @@ fn main() {
3131
}
3232
},
3333
_ => {
34-
println!("usage: {} [read_method|status].rs <output-dir>", args[0]);
34+
println!("usage: {} [read_method|status].rs <output-dir>", args.get(0));
3535
os::set_exit_status(1);
3636
}
3737
}

src/codegen/status.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,29 @@ fn StatusN(code: uint, reason: &'static str) -> HeadingOrStatus {
3434
}
3535

3636
impl Status {
37-
fn ident(&self) -> StrBuf {
37+
fn ident(&self) -> String {
3838
camel_case(self.reason)
3939
}
4040

41-
fn padded_ident(&self) -> StrBuf {
42-
let mut result = self.ident();
43-
result.push_str(self.reason_padding_spaces());
44-
result
41+
fn padded_ident(&self) -> String {
42+
self.ident().append(self.reason_padding_spaces().as_slice())
4543
}
4644

47-
fn reason_padding_spaces(&self) -> ~str {
45+
fn reason_padding_spaces(&self) -> String {
4846
" ".repeat(unsafe { longest_reason } - self.reason.len())
4947
}
5048
}
5149

5250
/// >>> camel_case("I'm a Tea-pot")
5351
/// "ImATeaPot"
54-
fn camel_case(msg: &str) -> StrBuf {
52+
fn camel_case(msg: &str) -> String {
5553
let msg = msg.replace("-", " ").replace("'", "");
56-
let mut result = StrBuf::with_capacity(msg.len());
54+
let mut result = String::with_capacity(msg.len());
5755
let mut capitalise = true;
58-
for c in msg.chars() {
56+
for c in msg.as_slice().chars() {
5957
let c = match capitalise {
60-
true => c.to_ascii().to_upper().to_char(),
61-
false => c.to_ascii().to_lower().to_char(),
58+
true => c.to_ascii().to_uppercase().to_char(),
59+
false => c.to_ascii().to_lowercase().to_char(),
6260
};
6361
// For a space, capitalise the next char
6462
capitalise = c == ' ';
@@ -178,7 +176,7 @@ pub enum Status {
178176
}
179177

180178
try!(out.write("
181-
UnregisteredStatus(u16, StrBuf),
179+
UnregisteredStatus(u16, String),
182180
}
183181
184182
impl Status {
@@ -200,13 +198,13 @@ impl Status {
200198
}
201199
202200
/// Get the reason phrase
203-
pub fn reason(&self) -> StrBuf {
201+
pub fn reason(&self) -> String {
204202
match *self {
205203
".as_bytes()));
206204
for &entry in entries.iter() {
207205
match entry {
208206
Heading(heading) => try!(write!(out, "\n // {}\n", heading)),
209-
Status(status) => try!(write!(out, " {} => StrBuf::from_str(\"{}\"),\n",
207+
Status(status) => try!(write!(out, " {} => String::from_str(\"{}\"),\n",
210208
status.padded_ident(), status.reason))
211209
}
212210
}
@@ -216,7 +214,7 @@ impl Status {
216214
}
217215
218216
/// Get a status from the code and reason
219-
pub fn from_code_and_reason(status: u16, reason: StrBuf) -> Status {
217+
pub fn from_code_and_reason(status: u16, reason: String) -> Status {
220218
let reason_lower = reason.as_slice().to_ascii_lower();
221219
match (status, reason_lower.as_slice()) {
222220
".as_bytes()));
@@ -238,7 +236,7 @@ impl Status {
238236
239237
impl fmt::Show for Status {
240238
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
241-
write!(f.buf, \"{} {}\", self.code(), self.reason())
239+
write!(f, \"{} {}\", self.code(), self.reason())
242240
}
243241
}
244242

src/examples/client/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![crate_id = "client"]
22

3+
extern crate debug;
34
extern crate http;
45
use http::client::RequestWriter;
56
use http::method::Get;
@@ -13,9 +14,9 @@ fn main() {
1314
let args = os::args();
1415
match args.len() {
1516
0 => unreachable!(),
16-
2 => make_and_print_request(args[1]),
17+
2 => make_and_print_request(args.get(1).as_slice()),
1718
_ => {
18-
println!("Usage: {} URL", args[0]);
19+
println!("Usage: {} URL", args.get(0));
1920
return;
2021
},
2122
};

src/examples/server/apache_fake/main.rs

+7-8
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(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"));
26+
w.headers.server = Some(String::from_str("Apache/2.2.22 (Ubuntu)"));
27+
//w.headers.last_modified = Some(String::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,21 @@ 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".to_owned(), // timezone abbreviation
4039
tm_nsec: 0, // nanoseconds
4140
});
4241
w.headers.etag = Some(headers::etag::EntityTag {
4342
weak: false,
44-
opaque_tag: StrBuf::from_str("501b29-b1-4a285ed47404a") });
43+
opaque_tag: String::from_str("501b29-b1-4a285ed47404a") });
4544
w.headers.accept_ranges = Some(headers::accept_ranges::RangeUnits(
4645
vec!(headers::accept_ranges::Bytes)));
4746
w.headers.content_length = Some(177);
48-
w.headers.vary = Some(StrBuf::from_str("Accept-Encoding"));
47+
w.headers.vary = Some(String::from_str("Accept-Encoding"));
4948
w.headers.content_type = Some(headers::content_type::MediaType {
50-
type_: StrBuf::from_str("text"),
51-
subtype: StrBuf::from_str("html"),
49+
type_: String::from_str("text"),
50+
subtype: String::from_str("html"),
5251
parameters: Vec::new()
5352
});
54-
w.headers.extensions.insert(StrBuf::from_str("X-Pad"), StrBuf::from_str("avoid browser bug"));
53+
w.headers.extensions.insert(String::from_str("X-Pad"), String::from_str("avoid browser bug"));
5554

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

src/examples/server/hello_world/main.rs

+4-4
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_: StrBuf::from_str("text"),
27-
subtype: StrBuf::from_str("plain"),
28-
parameters: vec!((StrBuf::from_str("charset"), StrBuf::from_str("UTF-8")))
26+
type_: String::from_str("text"),
27+
subtype: String::from_str("plain"),
28+
parameters: vec!((String::from_str("charset"), String::from_str("UTF-8")))
2929
});
30-
w.headers.server = Some(StrBuf::from_str("Example"));
30+
w.headers.server = Some(String::from_str("Example"));
3131

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

src/examples/server/info/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![crate_id = "info"]
55

66
extern crate time;
7+
extern crate debug;
78
extern crate http;
89

910
use std::io::net::ip::{SocketAddr, Ipv4Addr};
@@ -24,11 +25,11 @@ impl Server for InfoServer {
2425
fn handle_request(&self, r: &Request, w: &mut ResponseWriter) {
2526
w.headers.date = Some(time::now_utc());
2627
w.headers.content_type = Some(MediaType {
27-
type_: StrBuf::from_str("text"),
28-
subtype: StrBuf::from_str("html"),
29-
parameters: vec!((StrBuf::from_str("charset"), StrBuf::from_str("UTF-8")))
28+
type_: String::from_str("text"),
29+
subtype: String::from_str("html"),
30+
parameters: vec!((String::from_str("charset"), String::from_str("UTF-8")))
3031
});
31-
w.headers.server = Some(StrBuf::from_str("Rust Thingummy/0.0-pre"));
32+
w.headers.server = Some(String::from_str("Rust Thingummy/0.0-pre"));
3233
w.write(bytes!("<!DOCTYPE html><title>Rust HTTP server</title>")).unwrap();
3334

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

src/examples/server/request_uri/main.rs

+3-3
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(StrBuf::from_str("Rust Thingummy/0.1-pre"));
31+
w.headers.server = Some(String::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_: StrBuf::from_str("text"),
63-
subtype: StrBuf::from_str("html"),
62+
type_: String::from_str("text"),
63+
subtype: String::from_str("html"),
6464
parameters: Vec::new()
6565
});
6666

src/http/client/request.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,21 @@ impl<S: Reader + Writer = super::NetworkStream> RequestWriter<S> {
108108
pub fn new_request(method: Method, url: Url, use_ssl: bool, auto_detect_ssl: bool) -> IoResult<RequestWriter<S>> {
109109
let host = match url.port {
110110
None => Host {
111-
name: StrBuf::from_str(url.host),
111+
name: url.host.clone(),
112112
port: None,
113113
},
114114
Some(ref p) => Host {
115-
name: StrBuf::from_str(url.host),
116-
port: Some(from_str(*p).expect("You didn’t aught to give a bad port!")),
115+
name: url.host.clone(),
116+
port: Some(from_str(p.as_slice()).expect("You didn’t aught to give a bad port!")),
117117
},
118118
};
119119

120120
let remote_addr = try!(url_to_socket_addr(&url));
121-
info!("using ip address {} for {}", remote_addr.to_str(), url.host);
121+
info!("using ip address {} for {}", remote_addr.to_str(), url.host.as_slice());
122122

123123
fn url_to_socket_addr(url: &Url) -> IoResult<SocketAddr> {
124124
// Just grab the first IPv4 address
125-
let addrs = try!(get_host_addresses(url.host));
125+
let addrs = try!(get_host_addresses(url.host.as_slice()));
126126
let addr = addrs.move_iter().find(|&a| {
127127
match a {
128128
Ipv4Addr(..) => true,
@@ -135,7 +135,7 @@ impl<S: Reader + Writer = super::NetworkStream> RequestWriter<S> {
135135

136136
// Default to 80, using the port specified or 443 if the protocol is HTTPS.
137137
let port = match url.port {
138-
Some(ref p) => from_str(*p).expect("You didn’t aught to give a bad port!"),
138+
Some(ref p) => from_str(p.as_slice()).expect("You didn’t aught to give a bad port!"),
139139
// FIXME: case insensitivity?
140140
None => if url.scheme.as_slice() == "https" { 443 } else { 80 },
141141
};
@@ -186,7 +186,7 @@ impl<S: Connecter + Reader + Writer = super::NetworkStream> RequestWriter<S> {
186186

187187
self.stream = match self.remote_addr {
188188
Some(addr) => {
189-
let stream = try!(Connecter::connect(addr, self.url.host, self.use_ssl));
189+
let stream = try!(Connecter::connect(addr, self.url.host.as_slice(), self.use_ssl));
190190
Some(BufferedStream::new(stream))
191191
},
192192
None => fail!("connect() called before remote_addr was set"),

src/http/client/response.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::io::{Stream, IoResult, OtherIoError, IoError};
2-
use std::strbuf::StrBuf;
32
use client::request::RequestWriter;
43
use rfc2616::{CR, LF, SP};
54
use common::read_http_version;
@@ -66,7 +65,7 @@ impl<S: Stream> ResponseReader<S> {
6665
}
6766

6867
// Read the status reason
69-
let mut reason = StrBuf::new();
68+
let mut reason = String::new();
7069
loop {
7170
match stream.read_byte() {
7271
Ok(b) if b == CR => {

src/http/client/sslclients/none.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Connecter for NetworkStream {
2424
detail: None,
2525
})
2626
} else {
27-
let stream = try!(TcpStream::connect(addr));
27+
let stream = try!(TcpStream::connect(addr.ip.to_str().as_slice(), addr.port));
2828
Ok(NormalStream(stream))
2929
}
3030
}

0 commit comments

Comments
 (0)