Skip to content

Commit c0eff50

Browse files
committed
Rust update: The ToStr trait will be replaced wit Show
1 parent 104bfa5 commit c0eff50

File tree

7 files changed

+43
-59
lines changed

7 files changed

+43
-59
lines changed

src/codegen/status.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,6 @@ impl Status {
235235
}
236236
}
237237
238-
impl ToStr for Status {
239-
/// Produce the HTTP status message incorporating both code and message,
240-
/// e.g. `ImATeapot.to_str() == \"418 I'm a teapot\"`
241-
fn to_str(&self) -> ~str {
242-
format!(\"{} {}\", self.code().to_str(), self.reason())
243-
}
244-
}
245-
246238
impl fmt::Show for Status {
247239
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
248240
write!(f.buf, \"{} {}\", self.code(), self.reason())

src/http/headers/connection.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// whether they should be interpreted (I recall its being a header name thing for legacy code,
55
// perhaps I should normalise header case or some such thing?)
66

7+
use std::fmt;
78
use std::io::IoResult;
89
use headers::serialization_utils::normalise_header_name;
910

@@ -14,12 +15,13 @@ pub enum Connection {
1415
Token(~str),
1516
Close,
1617
}
17-
impl ToStr for Connection {
18-
fn to_str(&self) -> ~str {
19-
match *self {
20-
Token(ref s) => s.clone(),
21-
Close => ~"close",
22-
}
18+
19+
impl fmt::Show for Connection {
20+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21+
f.buf.write(match *self {
22+
Token(ref s) => s.as_bytes(),
23+
Close => "close".as_bytes(),
24+
})
2325
}
2426
}
2527

src/http/headers/content_type.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The Content-Type entity header, defined in RFC 2616, Section 14.17.
22
use headers::serialization_utils::{push_parameters, WriterUtil};
33
use std::io::IoResult;
4+
use std::fmt;
45

56
#[deriving(Clone, Eq)]
67
pub struct MediaType {
@@ -17,8 +18,8 @@ pub fn MediaType(type_: ~str, subtype: ~str, parameters: ~[(~str, ~str)]) -> Med
1718
}
1819
}
1920

20-
impl ToStr for MediaType {
21-
fn to_str(&self) -> ~str {
21+
impl fmt::Show for MediaType {
22+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2223
// Idea:
2324
//let s = ~"";
2425
//s.push_token(self.type_);
@@ -27,7 +28,7 @@ impl ToStr for MediaType {
2728
//s.push_parameters(self.parameters);
2829
//s
2930
let s = format!("{}/{}", self.type_, self.subtype);
30-
push_parameters(s, self.parameters)
31+
f.buf.write(push_parameters(s, self.parameters).as_bytes())
3132
}
3233
}
3334

src/http/headers/etag.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use headers::serialization_utils::{push_quoted_string, quoted_string, WriterUtil};
22
use std::io::IoResult;
3+
use std::fmt;
34

45
#[deriving(Clone, Eq)]
56
pub struct EntityTag {
@@ -21,12 +22,12 @@ pub fn strong_etag<S: Str>(opaque_tag: S) -> EntityTag {
2122
}
2223
}
2324

24-
impl ToStr for EntityTag {
25-
fn to_str(&self) -> ~str {
25+
impl fmt::Show for EntityTag {
26+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2627
if self.weak {
27-
push_quoted_string(~"W/", self.opaque_tag)
28+
f.buf.write(push_quoted_string(~"W/", self.opaque_tag).as_bytes())
2829
} else {
29-
quoted_string(self.opaque_tag)
30+
f.buf.write(quoted_string(self.opaque_tag).as_bytes())
3031
}
3132
}
3233
}

src/http/headers/host.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The Host request header, defined in RFC 2616, Section 14.23.
22
33
use std::io::Reader;
4+
use std::fmt;
45

56
/// A simple little thing for the host of a request
67
#[deriving(Clone, Eq)]
@@ -14,11 +15,12 @@ pub struct Host {
1415
/// include the scheme.
1516
port: Option<u16>,
1617
}
17-
impl ToStr for Host {
18-
fn to_str(&self) -> ~str {
18+
19+
impl fmt::Show for Host {
20+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1921
match self.port {
20-
Some(port) => format!("{}:{}", self.name, port.to_str()),
21-
None => self.name.clone(),
22+
Some(port) => write!(f.buf, "{}:{}", self.name, port.to_str()),
23+
None => f.buf.write(self.name.as_bytes()),
2224
}
2325
}
2426
}

src/http/method.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,6 @@ pub enum Method {
1717
ExtensionMethod(~str),
1818
}
1919

20-
impl ToStr for Method {
21-
/// Get the proper name of a method, e.g. `Get.to_str() == ~"GET"`
22-
fn to_str(&self) -> ~str {
23-
match *self {
24-
Options => ~"OPTIONS",
25-
Get => ~"GET",
26-
Head => ~"HEAD",
27-
Post => ~"POST",
28-
Put => ~"PUT",
29-
Delete => ~"DELETE",
30-
Trace => ~"TRACE",
31-
Connect => ~"CONNECT",
32-
Patch => ~"PATCH",
33-
ExtensionMethod(ref s) => (*s).clone(),
34-
}
35-
}
36-
}
37-
3820
impl FromStr for Method {
3921
/**
4022
* Get a *known* `Method` from an *ASCII* string, regardless of case.

src/http/rfc2616.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub fn is_separator(o: u8) -> bool {
141141
// see https://www.iana.org/assignments/http-parameters/http-parameters.xml
142142

143143
mod content_coding {
144+
use std::fmt;
145+
144146
/// Content-coding value tokens
145147
pub enum ValueToken {
146148
// An encoding format produced by the file compression program "gzip" (GNU zip) as described
@@ -171,14 +173,14 @@ mod content_coding {
171173
// - "exi": W3C Efficient XML Interchange
172174
// - "pack200-gzip" (Network Transfer Format for Java Archives)
173175
}
174-
impl ToStr for ValueToken {
175-
fn to_str(&self) -> ~str {
176-
match *self {
177-
Gzip => ~"gzip",
178-
Compress => ~"compress",
179-
Deflate => ~"deflate",
180-
Identity => ~"identity",
181-
}
176+
impl fmt::Show for ValueToken {
177+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
178+
f.buf.write(match *self {
179+
Gzip => "gzip".as_bytes(),
180+
Compress => "compress".as_bytes(),
181+
Deflate => "deflate".as_bytes(),
182+
Identity => "identity".as_bytes(),
183+
})
182184
}
183185
}
184186
impl FromStr for ValueToken {
@@ -196,6 +198,8 @@ mod content_coding {
196198
}
197199

198200
mod transfer_coding {
201+
use std::fmt;
202+
199203
/// Transfer-coding value tokens
200204
// Identity is in RFC 2616 but is withdrawn in RFC 2616 errata ID 408
201205
// http://www.rfc-editor.org/errata_search.php?rfc=2616&eid=408
@@ -205,14 +209,14 @@ mod transfer_coding {
205209
Compress, // See above
206210
Deflate, // See above
207211
}
208-
impl ToStr for ValueToken {
209-
fn to_str(&self) -> ~str {
210-
match *self {
211-
Chunked => ~"chunked",
212-
Gzip => ~"gzip",
213-
Compress => ~"compress",
214-
Deflate => ~"deflate",
215-
}
212+
impl fmt::Show for ValueToken {
213+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
214+
f.buf.write(match *self {
215+
Chunked => "chunked".as_bytes(),
216+
Gzip => "gzip".as_bytes(),
217+
Compress => "compress".as_bytes(),
218+
Deflate => "deflate".as_bytes(),
219+
})
216220
}
217221
}
218222
}

0 commit comments

Comments
 (0)