Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libhttp/codegen/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[feature(macro_rules)];
use std::io::{file_writer, Create, Truncate};
use std::os;

Expand Down
36 changes: 30 additions & 6 deletions src/libhttp/codegen/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ pub fn generate(output_dir: &Path) {
out.write_str("// This file is automatically generated file is used as http::status.

use std::fmt;
use std::num::IntConvertible;
use std::ascii::StrAsciiExt;

/// HTTP status code
Expand Down Expand Up @@ -254,19 +253,44 @@ impl fmt::Unsigned for Status {
}


impl IntConvertible for Status {
impl ToPrimitive for Status {

/// Equivalent to `self.code()`
fn to_int(&self) -> int {
self.code() as int
fn to_i64(&self) -> Option<i64> {
Some(self.code() as i64)
}
}

impl FromPrimitive for Status {

/// Get a *registered* status code from the number of its status code.
///
/// This will fail if an unknown code is passed.
///
/// For example, `from_int(200)` will return `OK`.
fn from_int(n: int) -> Status {
fn from_i64(n: i64) -> Option<Status> {
match n {
");
let mut matched_numbers = HashSet::new();
for &entry in entries.iter() {
match entry {
Left(heading) => out.write_str(format!("\n // {}\n", heading)),
Right(status) => {
if !matched_numbers.contains(&status.code) {
// Purpose: FailedDependency and MethodFailure both use 424,
// but clearly they mustn't both go in here
out.write_str(format!(" {:u} => Some({}),\n", status.code, status.ident()));
matched_numbers.insert(status.code);
}
},
}
}
out.write_str("
_ => { fail!(format!(\"No registered HTTP status code {}\", n)); }
}
}

fn from_u64(n: u64) -> Option<Status> {
match n {
");
let mut matched_numbers = HashSet::new();
Expand All @@ -277,7 +301,7 @@ impl IntConvertible for Status {
if !matched_numbers.contains(&status.code) {
// Purpose: FailedDependency and MethodFailure both use 424,
// but clearly they mustn't both go in here
out.write_str(format!(" {:u} => {},\n", status.code, status.ident()));
out.write_str(format!(" {:u} => Some({}),\n", status.code, status.ident()));
matched_numbers.insert(status.code);
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/libhttp/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[feature(macro_rules)];
#[link(name = "http",
vers = "0.1-pre",
uuid = "d2ad8df0-547a-4ce1-99c6-a9da3b98fb3e",
Expand All @@ -11,6 +12,7 @@
//#[deny(missing_doc)];

#[macro_escape];
#[feature(globs)];

extern mod extra;

Expand Down