diff --git a/contrib/src/json.rs b/contrib/src/json.rs index fe00f029..a461127a 100644 --- a/contrib/src/json.rs +++ b/contrib/src/json.rs @@ -111,7 +111,7 @@ impl FromData for Json { impl Responder<'static> for Json { fn respond_to(self, req: &Request) -> response::Result<'static> { serde_json::to_string(&self.0).map(|string| { - content::JSON(string).respond_to(req).unwrap() + content::Json(string).respond_to(req).unwrap() }).map_err(|e| { error_!("JSON failed to serialize: {:?}", e); Status::InternalServerError diff --git a/examples/content_types/src/main.rs b/examples/content_types/src/main.rs index d9f76d27..c705e95b 100644 --- a/examples/content_types/src/main.rs +++ b/examples/content_types/src/main.rs @@ -21,22 +21,22 @@ struct Person { // preferred media type in the Accept header is matched against the `format` in // the route attribute. #[get("//", format = "application/json")] -fn get_hello(name: String, age: u8) -> content::JSON { +fn get_hello(name: String, age: u8) -> content::Json { // In a real application, we'd use the JSON contrib type. let person = Person { name: name, age: age, }; - content::JSON(serde_json::to_string(&person).unwrap()) + content::Json(serde_json::to_string(&person).unwrap()) } // In a `POST` request and all other payload supporting request types, the // content type is matched against the `format` in the route attribute. #[post("/", format = "text/plain", data = "")] -fn post_hello(age: u8, name: String) -> content::JSON { +fn post_hello(age: u8, name: String) -> content::Json { let person = Person { name: name, age: age, }; - content::JSON(serde_json::to_string(&person).unwrap()) + content::Json(serde_json::to_string(&person).unwrap()) } #[error(404)] -fn not_found(request: &Request) -> content::HTML { +fn not_found(request: &Request) -> content::Html { let html = match request.format() { Some(ref mt) if !mt.is_json() && !mt.is_plain() => { format!("

'{}' requests are not supported.

", mt) @@ -46,7 +46,7 @@ fn not_found(request: &Request) -> content::HTML { request.uri()) }; - content::HTML(html) + content::Html(html) } fn main() { diff --git a/examples/errors/src/main.rs b/examples/errors/src/main.rs index 8ce806cf..d2780f65 100644 --- a/examples/errors/src/main.rs +++ b/examples/errors/src/main.rs @@ -13,8 +13,8 @@ fn hello(name: String, age: i8) -> String { } #[error(404)] -fn not_found(req: &rocket::Request) -> content::HTML { - content::HTML(format!("

Sorry, but '{}' is not a valid path!

+fn not_found(req: &rocket::Request) -> content::Html { + content::Html(format!("

Sorry, but '{}' is not a valid path!

Try visiting /hello/<name>/<age> instead.

", req.uri())) } diff --git a/examples/state/src/main.rs b/examples/state/src/main.rs index 4a750f7d..7fe08aaf 100644 --- a/examples/state/src/main.rs +++ b/examples/state/src/main.rs @@ -13,11 +13,11 @@ use rocket::response::content; struct HitCount(AtomicUsize); #[get("/")] -fn index(hit_count: State) -> content::HTML { +fn index(hit_count: State) -> content::Html { hit_count.0.fetch_add(1, Ordering::Relaxed); let msg = "Your visit has been recorded!"; let count = format!("Visits: {}", count(hit_count)); - content::HTML(format!("{}

{}", msg, count)) + content::Html(format!("{}

{}", msg, count)) } #[get("/count")] diff --git a/lib/src/catcher.rs b/lib/src/catcher.rs index fd53315c..67873aae 100644 --- a/lib/src/catcher.rs +++ b/lib/src/catcher.rs @@ -158,7 +158,7 @@ macro_rules! default_errors { $( fn $fn_name<'r>(_: Error, req: &'r Request) -> response::Result<'r> { status::Custom(Status::from_code($code).unwrap(), - content::HTML(error_page_template!($code, $name, $description)) + content::Html(error_page_template!($code, $name, $description)) ).respond_to(req) } diff --git a/lib/src/response/content.rs b/lib/src/response/content.rs index 1ad33259..f4a7cbd8 100644 --- a/lib/src/response/content.rs +++ b/lib/src/response/content.rs @@ -10,16 +10,16 @@ //! //! # Example //! -//! The following snippet creates an `HTML` content response for a string. +//! The following snippet creates an `Html` content response for a string. //! Normally, raw strings set their response Content-Type to `text/plain`. By -//! using the `HTML` content response, the Content-Type will be set to +//! using the `Html` content response, the Content-Type will be set to //! `text/html` instead. //! //! ```rust //! use rocket::response::content; //! //! # #[allow(unused_variables)] -//! let response = content::HTML("

Hello, world!

"); +//! let response = content::Html("

Hello, world!

"); //! ``` use request::Request; @@ -57,7 +57,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Content { } macro_rules! ctrs { - ($($name:ident: $name_str:expr, $ct_str:expr),+) => { + ($($name:ident: $ct:ident, $name_str:expr, $ct_str:expr),+) => { $( #[doc="Override the `Content-Type` of the response to "] #[doc=$name_str] @@ -73,7 +73,7 @@ macro_rules! ctrs { /// remainder of the response to the wrapped responder. impl<'r, R: Responder<'r>> Responder<'r> for $name { fn respond_to(self, req: &Request) -> Result, Status> { - Content(ContentType::$name, self.0).respond_to(req) + Content(ContentType::$ct, self.0).respond_to(req) } } )+ @@ -81,12 +81,12 @@ macro_rules! ctrs { } ctrs! { - JSON: "JSON", "application/json", - XML: "XML", "text/xml", - MsgPack: "MessagePack", "application/msgpack", - HTML: "HTML", "text/html", - Plain: "plain text", "text/plain", - CSS: "CSS", "text/css", - JavaScript: "JavaScript", "application/javascript" + Json: JSON, "JSON", "application/json", + Xml: XML, "XML", "text/xml", + MsgPack: MsgPack, "MessagePack", "application/msgpack", + Html: HTML, "HTML", "text/html", + Plain: Plain, "plain text", "text/plain", + Css: CSS, "CSS", "text/css", + JavaScript: JavaScript, "JavaScript", "application/javascript" } diff --git a/lib/tests/head_handling.rs b/lib/tests/head_handling.rs index b97ebb90..4e20c9f2 100644 --- a/lib/tests/head_handling.rs +++ b/lib/tests/head_handling.rs @@ -16,8 +16,8 @@ fn index() -> &'static str { } #[head("/other")] -fn other() -> content::JSON<()> { - content::JSON(()) +fn other() -> content::Json<()> { + content::Json(()) } mod tests { diff --git a/site/guide/responses.md b/site/guide/responses.md index 34cdab99..ee5fc35c 100644 --- a/site/guide/responses.md +++ b/site/guide/responses.md @@ -48,7 +48,7 @@ fn new(id: usize) -> status::Accepted { Similarly, the types in the [`content` module](https://api.rocket.rs/rocket/response/content/index.html) can be used to override the Content-Type of a response. For instance, to set the Content-Type -an `&'static str` to JSON, you can use the [`content::JSON`] type as follows: +an `&'static str` to JSON, you can use the [`content::Json`] type as follows: ```rust use rocket::response::content; @@ -60,7 +60,7 @@ fn json() -> content::Json<&'static str> { ``` [`Accepted`]: https://api.rocket.rs/rocket/response/status/struct.Accepted.html -[`content::JSON`]: https://api.rocket.rs/rocket/response/content/struct.Json.html +[`content::Json`]: https://api.rocket.rs/rocket/response/content/struct.Json.html ### Errors