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

Commit 642a9ce

Browse files
committed
Stop using Either, removed in rust-lang/rust#11149
1 parent 0eebf34 commit 642a9ce

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/codegen/status.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
use std::ascii::StrAsciiExt;
1111
use std::hashmap::HashSet;
12-
use std::either::{Either, Left, Right};
1312
use std::vec;
1413
use std::io::Writer;
1514
use super::get_writer;
1615

17-
type HeadingOrStatus = Either<&'static str, Status>;
16+
enum HeadingOrStatus {
17+
Heading(&'static str),
18+
Status(Status),
19+
}
1820

1921
struct Status {
2022
code: uint,
@@ -24,12 +26,12 @@ struct Status {
2426

2527
/// Status with comment
2628
fn StatusC(code: uint, reason: &'static str, comment: &'static str) -> HeadingOrStatus {
27-
Right(Status { code: code, reason: reason, comment: Some(comment) })
29+
Status(Status { code: code, reason: reason, comment: Some(comment) })
2830
}
2931

3032
/// Status without comment
3133
fn StatusN(code: uint, reason: &'static str) -> HeadingOrStatus {
32-
Right(Status { code: code, reason: reason, comment: None })
34+
Status(Status { code: code, reason: reason, comment: None })
3335
}
3436

3537
impl Status {
@@ -72,12 +74,12 @@ static mut longest_reason: uint = 0;
7274
pub fn generate(output_dir: &Path) {
7375
let mut out = get_writer(output_dir, "status.rs");
7476
let entries = [
75-
Left("1xx Informational"),
77+
Heading("1xx Informational"),
7678
StatusN(100, "Continue"),
7779
StatusN(101, "Switching Protocols"),
7880
StatusC(102, "Processing", "WebDAV; RFC 2518"),
7981

80-
Left("2xx Success"),
82+
Heading("2xx Success"),
8183
StatusN(200, "OK"),
8284
StatusN(201, "Created"),
8385
StatusN(202, "Accepted"),
@@ -89,7 +91,7 @@ pub fn generate(output_dir: &Path) {
8991
StatusC(208, "Already Reported", "WebDAV; RFC 5842"),
9092
StatusC(226, "IM Used", "RFC 3229"),
9193

92-
Left("3xx Redirection"),
94+
Heading("3xx Redirection"),
9395
StatusN(300, "Multiple Choices"),
9496
StatusN(301, "Moved Permanently"),
9597
StatusN(302, "Found"),
@@ -100,7 +102,7 @@ pub fn generate(output_dir: &Path) {
100102
StatusC(307, "Temporary Redirect", "since HTTP/1.1"),
101103
StatusC(308, "Permanent Redirect", "approved as experimental RFC: http://tools.ietf.org/html/draft-reschke-http-status-308"),
102104

103-
Left("4xx Client Error"),
105+
Heading("4xx Client Error"),
104106
StatusN(400, "Bad Request"),
105107
StatusN(401, "Unauthorized"),
106108
StatusN(402, "Payment Required"),
@@ -132,7 +134,7 @@ pub fn generate(output_dir: &Path) {
132134
StatusC(431, "Request Header Fields Too Large", "RFC 6585"),
133135
StatusC(451, "Unavailable For Legal Reasons", "Internet draft"),
134136

135-
Left("5xx Server Error"),
137+
Heading("5xx Server Error"),
136138
StatusN(500, "Internal Server Error"),
137139
StatusN(501, "Not Implemented"),
138140
StatusN(502, "Bad Gateway"),
@@ -147,12 +149,12 @@ pub fn generate(output_dir: &Path) {
147149
];
148150
unsafe {
149151
longest_ident = entries.iter().map(|&e| match e {
150-
Left(_heading) => 0,
151-
Right(status) => status.ident().len(),
152+
Heading(_heading) => 0,
153+
Status(status) => status.ident().len(),
152154
}).max_by(|&i| i).unwrap();
153155
longest_reason = entries.iter().map(|&e| match e {
154-
Left(_heading) => 0,
155-
Right(status) => status.reason.len(),
156+
Heading(_heading) => 0,
157+
Status(status) => status.reason.len(),
156158
}).max_by(|&i| i).unwrap();
157159
}
158160
out.write("// This file is automatically generated file is used as http::status.
@@ -166,8 +168,8 @@ pub enum Status {
166168
".as_bytes());
167169
for &entry in entries.iter() {
168170
match entry {
169-
Left(heading) => write!(out, "\n // {}\n", heading),
170-
Right(status) => match status.comment {
171+
Heading(heading) => write!(out, "\n // {}\n", heading),
172+
Status(status) => match status.comment {
171173
None => write!(out, " {},\n", status.ident()),
172174
Some(comment) => write!(out, " {}, // {}\n", status.ident(), comment),
173175
},
@@ -186,8 +188,8 @@ impl Status {
186188
".as_bytes());
187189
for &entry in entries.iter() {
188190
match entry {
189-
Left(heading) => write!(out, "\n // {}\n", heading),
190-
Right(status) => write!(out, " {} => {},\n",
191+
Heading(heading) => write!(out, "\n // {}\n", heading),
192+
Status(status) => write!(out, " {} => {},\n",
191193
status.padded_ident(), status.code),
192194
}
193195
}
@@ -202,8 +204,8 @@ impl Status {
202204
".as_bytes());
203205
for &entry in entries.iter() {
204206
match entry {
205-
Left(heading) => write!(out, "\n // {}\n", heading),
206-
Right(status) => write!(out, " {} => ~\"{}\",\n",
207+
Heading(heading) => write!(out, "\n // {}\n", heading),
208+
Status(status) => write!(out, " {} => ~\"{}\",\n",
207209
status.padded_ident(), status.reason)
208210
}
209211
}
@@ -219,8 +221,8 @@ impl Status {
219221
".as_bytes());
220222
for &entry in entries.iter() {
221223
match entry {
222-
Left(heading) => write!(out, "\n // {}\n", heading),
223-
Right(status) => write!(out, " ({}, \"{}\"){} => {},\n",
224+
Heading(heading) => write!(out, "\n // {}\n", heading),
225+
Status(status) => write!(out, " ({}, \"{}\"){} => {},\n",
224226
status.code,
225227
status.reason.to_ascii_lower(),
226228
status.reason_padding_spaces(),
@@ -292,8 +294,8 @@ impl FromPrimitive for Status {
292294
let mut matched_numbers = HashSet::new();
293295
for &entry in entries.iter() {
294296
match entry {
295-
Left(heading) => write!(out, "\n // {}\n", heading),
296-
Right(status) => {
297+
Heading(heading) => write!(out, "\n // {}\n", heading),
298+
Status(status) => {
297299
if !matched_numbers.contains(&status.code) {
298300
// Purpose: FailedDependency and MethodFailure both use 424,
299301
// but clearly they mustn't both go in here

0 commit comments

Comments
 (0)