Skip to content

Commit bec1145

Browse files
committed
Merge pull request chris-morgan#89 from Ogeon/master
Rust update: ~str and tm_zone in time::Tm are gone and some more
2 parents 5e561db + 7a38ba9 commit bec1145

26 files changed

+309
-315
lines changed

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<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

Lines changed: 8 additions & 8 deletions
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/status.rs

Lines changed: 13 additions & 15 deletions
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()));

src/examples/client/main.rs

Lines changed: 2 additions & 1 deletion
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,7 +14,7 @@ fn main() {
1314
let args = os::args();
1415
match args.len() {
1516
0 => unreachable!(),
16-
2 => make_and_print_request(*args.get(1)),
17+
2 => make_and_print_request(args.get(1).as_slice()),
1718
_ => {
1819
println!("Usage: {} URL", args.get(0));
1920
return;

src/examples/server/apache_fake/main.rs

Lines changed: 7 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(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

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_: 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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 3 additions & 3 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(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/response.rs

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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.ip.to_str(), addr.port));
27+
let stream = try!(TcpStream::connect(addr.ip.to_str().as_slice(), addr.port));
2828
Ok(NormalStream(stream))
2929
}
3030
}

src/http/client/sslclients/openssl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub enum NetworkStream {
1818

1919
impl Connecter for NetworkStream {
2020
fn connect(addr: SocketAddr, _host: &str, use_ssl: bool) -> IoResult<NetworkStream> {
21-
let stream = try!(TcpStream::connect(addr.ip.to_str(), addr.port));
21+
let stream = try!(TcpStream::connect(addr.ip.to_str().as_slice(), addr.port));
2222
if use_ssl {
2323
let ssl_stream = SslStream::new(&SslContext::new(Sslv23), stream);
2424
Ok(SslProtectedStream(ssl_stream))

src/http/headers/accept_ranges.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ascii::StrAsciiExt;
77
// RFC 2616: range-unit = bytes-unit | other-range-unit
88
pub enum RangeUnit {
99
Bytes, // bytes-unit = "bytes"
10-
OtherRangeUnit(StrBuf), // other-range-unit = token
10+
OtherRangeUnit(String), // other-range-unit = token
1111
}
1212

1313
#[deriving(Clone,Eq)]
@@ -31,7 +31,7 @@ impl super::HeaderConvertible for AcceptableRanges {
3131
match token.as_slice() {
3232
"bytes" => range_units.push(Bytes),
3333
"none" if range_units.len() == 0 => return Some(NoAcceptableRanges),
34-
_ => range_units.push(OtherRangeUnit(StrBuf::from_str(token))),
34+
_ => range_units.push(OtherRangeUnit(token)),
3535
}
3636
},
3737
None => break,
@@ -55,11 +55,11 @@ impl super::HeaderConvertible for AcceptableRanges {
5555
}
5656
}
5757

58-
fn http_value(&self) -> StrBuf {
58+
fn http_value(&self) -> String {
5959
match *self {
60-
NoAcceptableRanges => StrBuf::from_str("none"),
60+
NoAcceptableRanges => String::from_str("none"),
6161
RangeUnits(ref range_units) => {
62-
let mut result = StrBuf::new();
62+
let mut result = String::new();
6363
for ru in range_units.iter() {
6464
match ru {
6565
&Bytes => result.push_str("bytes"),

src/http/headers/connection.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use headers::serialization_utils::normalise_header_name;
1212
/// normalised header case (e.g. "Keep-Alive").
1313
#[deriving(Clone, Eq)]
1414
pub enum Connection {
15-
Token(StrBuf),
15+
Token(String),
1616
Close,
1717
}
1818

@@ -48,9 +48,9 @@ impl super::HeaderConvertible for Connection {
4848
})
4949
}
5050

51-
fn http_value(&self) -> StrBuf {
51+
fn http_value(&self) -> String {
5252
match *self {
53-
Close => StrBuf::from_str("close"),
53+
Close => String::from_str("close"),
5454
Token(ref s) => s.clone(),
5555
}
5656
}
@@ -62,16 +62,16 @@ fn test_connection() {
6262
assert_interpretation_correct,
6363
assert_invalid};
6464
assert_conversion_correct("close", vec!(Close));
65-
assert_conversion_correct("Foo", vec!(Token(StrBuf::from_str("Foo"))));
66-
assert_conversion_correct("Foo, Keep-Alive", vec!(Token(StrBuf::from_str("Foo")), Token(StrBuf::from_str("Keep-Alive"))));
67-
assert_conversion_correct("Foo, close", vec!(Token(StrBuf::from_str("Foo")), Close));
68-
assert_conversion_correct("close, Bar", vec!(Close, Token(StrBuf::from_str("Bar"))));
65+
assert_conversion_correct("Foo", vec!(Token(String::from_str("Foo"))));
66+
assert_conversion_correct("Foo, Keep-Alive", vec!(Token(String::from_str("Foo")), Token(String::from_str("Keep-Alive"))));
67+
assert_conversion_correct("Foo, close", vec!(Token(String::from_str("Foo")), Close));
68+
assert_conversion_correct("close, Bar", vec!(Close, Token(String::from_str("Bar"))));
6969

7070
assert_interpretation_correct("close", vec!(Close));
71-
assert_interpretation_correct("foo", vec!(Token(StrBuf::from_str("Foo"))));
72-
assert_interpretation_correct("close \r\n , keep-ALIVE", vec!(Close, Token(StrBuf::from_str("Keep-Alive"))));
73-
assert_interpretation_correct("foo,close", vec!(Token(StrBuf::from_str("Foo")), Close));
74-
assert_interpretation_correct("close, bar", vec!(Close, Token(StrBuf::from_str("Bar"))));
71+
assert_interpretation_correct("foo", vec!(Token(String::from_str("Foo"))));
72+
assert_interpretation_correct("close \r\n , keep-ALIVE", vec!(Close, Token(String::from_str("Keep-Alive"))));
73+
assert_interpretation_correct("foo,close", vec!(Token(String::from_str("Foo")), Close));
74+
assert_interpretation_correct("close, bar", vec!(Close, Token(String::from_str("Bar"))));
7575
assert_interpretation_correct("CLOSE", Close);
7676

7777
assert_invalid::<Vec<Connection>>("foo bar");

0 commit comments

Comments
 (0)