summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/examples/dev_mode.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
commit17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch)
tree3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /vendor/handlebars/examples/dev_mode.rs
parentAdding upstream version 1.64.0+dfsg1. (diff)
downloadrustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.tar.xz
rustc-17d40c6057c88f4c432b0d7bac88e1b84cb7e67f.zip
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/handlebars/examples/dev_mode.rs')
-rw-r--r--vendor/handlebars/examples/dev_mode.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/vendor/handlebars/examples/dev_mode.rs b/vendor/handlebars/examples/dev_mode.rs
index 99017474f..3256eed37 100644
--- a/vendor/handlebars/examples/dev_mode.rs
+++ b/vendor/handlebars/examples/dev_mode.rs
@@ -2,10 +2,9 @@ use std::sync::Arc;
use handlebars::Handlebars;
use serde_json::json;
-use warp::{self, Filter};
+use tiny_http::{Response, Server};
-#[tokio::main]
-async fn main() {
+fn handlebars() -> Handlebars<'static> {
let mut reg = Handlebars::new();
// enable dev mode for template reloading
reg.set_dev_mode(true);
@@ -14,14 +13,19 @@ async fn main() {
reg.register_template_file("tpl", "./examples/dev_mode/template.hbs")
.unwrap();
- let hbs = Arc::new(reg);
- let route = warp::get().map(move || {
+ reg
+}
+
+fn main() {
+ let hbs = Arc::new(handlebars());
+
+ let server = Server::http("127.0.0.1:3030").expect("Failed to start demo server.");
+ println!("Edit ./examples/dev_mode/template.hbs and request http://localhost:3030 to see the change on the fly.");
+
+ for req in server.incoming_requests() {
let result = hbs
.render("tpl", &json!({"model": "t14s", "brand": "Thinkpad"}))
.unwrap_or_else(|e| e.to_string());
- warp::reply::html(result)
- });
-
- println!("Edit ./examples/dev_mode/template.hbs and request http://localhost:3030 to see the change on the run.");
- warp::serve(route).run(([127, 0, 0, 1], 3030)).await;
+ req.respond(Response::from_string(result)).unwrap();
+ }
}