From 66320b0bdb3bd196af78117cbad0b893df6d19eb Mon Sep 17 00:00:00 2001 From: Bodil Stokke Date: Mon, 8 Apr 2019 16:47:00 +0100 Subject: [PATCH] Replace Rocket example with Iron example, which builds on stable rustc. --- Cargo.toml | 2 +- examples/{rocket => iron}/Cargo.toml | 4 ++-- examples/{rocket => iron}/src/main.rs | 31 +++++++++++---------------- 3 files changed, 15 insertions(+), 22 deletions(-) rename examples/{rocket => iron}/Cargo.toml (78%) rename examples/{rocket => iron}/src/main.rs (72%) diff --git a/Cargo.toml b/Cargo.toml index c73cdc8..31ea471 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [ "typed-html", "macros", "examples/stdweb", - "examples/rocket", + "examples/iron", "examples/dodrio/counter", "examples/dodrio/todomvc", "ui", diff --git a/examples/rocket/Cargo.toml b/examples/iron/Cargo.toml similarity index 78% rename from examples/rocket/Cargo.toml rename to examples/iron/Cargo.toml index 1e83183..04f80a7 100644 --- a/examples/rocket/Cargo.toml +++ b/examples/iron/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "typed-html-rocket-test" +name = "typed-html-iron-test" version = "0.1.0" edition = "2018" authors = ["Bodil Stokke "] @@ -7,4 +7,4 @@ authors = ["Bodil Stokke "] [dependencies] typed-html-macros = { path = "../../macros" } typed-html = { path = "../../typed-html" } -rocket = "0.4.0-rc.1" +iron = "0.6.0" diff --git a/examples/rocket/src/main.rs b/examples/iron/src/main.rs similarity index 72% rename from examples/rocket/src/main.rs rename to examples/iron/src/main.rs index 440403b..065deaa 100644 --- a/examples/rocket/src/main.rs +++ b/examples/iron/src/main.rs @@ -1,27 +1,19 @@ #![recursion_limit = "256"] -#![feature(proc_macro_hygiene, decl_macro)] -extern crate rocket; -extern crate typed_html; -extern crate typed_html_macros; - -use rocket::http::{ContentType, Status}; -use rocket::response::{Responder, Result}; -use rocket::{get, routes, Request, Response}; -use std::io::Cursor; +use iron::headers::ContentType; +use iron::modifier::Modifier; +use iron::prelude::*; +use iron::status; use typed_html::elements::FlowContent; use typed_html::types::LinkType; use typed_html::{dom::DOMTree, html, text, OutputType}; struct Html(DOMTree); -impl<'r> Responder<'r> for Html { - fn respond_to(self, _request: &Request) -> Result<'r> { - Ok(Response::build() - .status(Status::Ok) - .header(ContentType::HTML) - .sized_body(Cursor::new(self.0.to_string())) - .finalize()) +impl Modifier for Html { + fn modify(self, res: &mut Response) { + res.body = Some(Box::new(self.0.to_string())); + res.headers.set(ContentType::html()); } } @@ -46,9 +38,8 @@ fn doc(tree: Box>) -> DOMTree { ) } -#[get("/")] fn index() -> Html { - let a = false; + let a = true; Html(doc(html!(

"Hello Kitty!"

@@ -68,5 +59,7 @@ fn index() -> Html { } fn main() { - rocket::ignite().mount("/", routes![index]).launch(); + Iron::new(|_: &mut Request| Ok(Response::with((status::Ok, index())))) + .http("localhost:1337") + .unwrap(); }