Skip to content

Commit 9e2b4ea

Browse files
committed
fix(enums): Add pub use/namespacing where required
BREAKING CHANGE: This change will require downstream users to reference mime types using their namespace. i.e. MediaType::Json I added pub use in places where the enums wouldn't be poluting user namespaces with a large amount of names.
1 parent fc93f5a commit 9e2b4ea

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ git = "https://github.com/nickel-org/groupable-rs"
3333

3434
path = "nickel_macros"
3535

36+
[dependencies.time]
37+
38+
git = "https://github.com/rust-lang/time"
39+
3640
[[example]]
3741

3842
name = "example"

src/favicon_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use request;
88
use response;
99
use middleware::{Action, Halt, Continue, Middleware};
1010
use nickel_error::NickelError;
11-
use mimes::Ico;
11+
use mimes::MediaType;
1212

1313
pub struct FaviconHandler {
1414
icon: Vec<u8>,
@@ -75,7 +75,7 @@ impl FaviconHandler {
7575

7676
pub fn send_favicon (&self, req: &request::Request, res: &mut response::Response) {
7777
debug!("{} {}", req.origin.method, self.icon_path.display());
78-
res.content_type(Ico);
78+
res.content_type(MediaType::Ico);
7979
res.send(self.icon.as_slice());
8080
}
8181
}

src/middleware.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use request::Request;
22
use response::Response;
33
use nickel_error::NickelError;
44

5+
pub use self::Action::{Continue, Halt};
6+
57
pub type MiddlewareResult = Result<Action, NickelError>;
68

79
#[deriving(PartialEq)]

src/mimes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use http::headers::content_type;
2-
use std::from_str::FromStr;
2+
use std::str::FromStr;
33

44
macro_rules! mimes(
55
($($t:expr { $($name:ident, $as_s:pat, $subt:expr,)+ })+) => (
@@ -17,7 +17,7 @@ macro_rules! mimes(
1717
let (ty, subty) = match ty {
1818
$(
1919
$(
20-
$name => ($t, $subt)
20+
MediaType::$name => ($t, $subt)
2121
),*
2222
),*
2323
};
@@ -34,7 +34,7 @@ macro_rules! mimes(
3434
match s {
3535
$(
3636
$(
37-
$as_s => Some($name)
37+
$as_s => Some(MediaType::$name)
3838
),*
3939
),*,
4040
_ => None

src/nickel_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::str::SendStr;
22
use http::status::Status;
33

4+
pub use self::NickelErrorKind::{ErrorWithStatusCode, UserDefinedError, Other};
5+
46
/// NickelError is the basic error type for HTTP errors as well as user defined errors.
57
/// One can pattern match against the `kind` property to handle the different cases.
68

src/router/request_handler.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use http::headers;
55
use std::fmt::Show;
66
use middleware::{MiddlewareResult, Halt};
77
use serialize::json;
8-
use mimes::{MediaType, Html, Json};
8+
use mimes::MediaType;
99

1010
/// Handles a HTTP request
1111
/// This is pre-implemented for any function which takes a
@@ -36,29 +36,29 @@ pub trait ResponseFinalizer {
3636

3737
impl ResponseFinalizer for () {
3838
fn respond(self, res: &mut Response) -> MiddlewareResult {
39-
maybe_set_type(res, Html);
39+
maybe_set_type(res, MediaType::Html);
4040
Ok(Halt)
4141
}
4242
}
4343

4444
impl ResponseFinalizer for MiddlewareResult {
4545
fn respond(self, res: &mut Response) -> MiddlewareResult {
46-
maybe_set_type(res, Html);
46+
maybe_set_type(res, MediaType::Html);
4747
self
4848
}
4949
}
5050

5151
impl ResponseFinalizer for json::Json {
5252
fn respond(self, res: &mut Response) -> MiddlewareResult {
53-
maybe_set_type(res, Json);
53+
maybe_set_type(res, MediaType::Json);
5454
res.send(json::encode(&self));
5555
Ok(Halt)
5656
}
5757
}
5858

5959
impl<'a, S: Show> ResponseFinalizer for &'a [S] {
6060
fn respond(self, res: &mut Response) -> MiddlewareResult {
61-
maybe_set_type(res, Html);
61+
maybe_set_type(res, MediaType::Html);
6262
res.origin.status = status::Ok;
6363
for ref s in self.iter() {
6464
// FIXME : failure unhandled
@@ -83,7 +83,7 @@ macro_rules! dual_impl(
8383
dual_impl!(&'a str,
8484
String
8585
|self, res| {
86-
maybe_set_type(res, Html);
86+
maybe_set_type(res, MediaType::Html);
8787
res.origin.status = status::Ok;
8888
res.send(self);
8989
Ok(Halt)
@@ -92,7 +92,7 @@ dual_impl!(&'a str,
9292
dual_impl!((status::Status, &'a str),
9393
(status::Status, String)
9494
|self, res| {
95-
maybe_set_type(res, Html);
95+
maybe_set_type(res, MediaType::Html);
9696
let (status, data) = self;
9797
res.origin.status = status;
9898
res.send(data);
@@ -102,7 +102,7 @@ dual_impl!((status::Status, &'a str),
102102
dual_impl!((uint, &'a str),
103103
(uint, String)
104104
|self, res| {
105-
maybe_set_type(res, Html);
105+
maybe_set_type(res, MediaType::Html);
106106
let (status, data) = self;
107107
match FromPrimitive::from_uint(status) {
108108
Some(status) => {
@@ -124,7 +124,7 @@ dual_impl!((status::Status, &'a str, Vec<headers::response::Header>),
124124
for header in headers.into_iter() {
125125
res.origin.headers.insert(header);
126126
}
127-
maybe_set_type(res, Html);
127+
maybe_set_type(res, MediaType::Html);
128128
res.send(data);
129129
Ok(Halt)
130130
})

0 commit comments

Comments
 (0)