Inital commit

master
Tait Hoyem 2 years ago
commit 593cfb02dd

@ -0,0 +1,13 @@
[package]
name = "localdriver"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = "0.5.0-rc.2"
[dependencies.rocket_dyn_templates]
version = "0.1.0-rc.2"
features = ["tera"]

@ -0,0 +1,50 @@
#[macro_use] extern crate rocket;
use rocket::tokio::time::{sleep, Duration};
use rocket::form::Form;
use rocket_dyn_templates::{Template, context};
#[derive(FromForm)]
struct Note<'r> {
title: &'r str,
description: &'r str,
}
#[post("/form", data="<note>")]
async fn form(note: Form<Note<'_>>) -> String {
format!("New note: {} with description\n{}.", note.title, note.description)
}
#[get("/hello/<name>")]
async fn hello(name: &str) -> String {
format!("Hello, {}", name)
}
fn test1() -> Vec {
Vec::new()
}
#[get("/")]
async fn index() -> Template {
let notes: Vec<Note<'_>> = Vec::new();
notes.append(Note{ title: "Test", description: "Test" });
Template::render("index", context!{
title: "Home",
name: "Tait Hoyem"
})
}
#[get("/delay/<seconds>")]
async fn delay(seconds: u64) -> String {
sleep(Duration::from_secs(seconds)).await;
format!("Waited for {} seconds", seconds)
}
#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
let _rocket = rocket::build()
.mount("/", routes![index, delay, hello, form])
.attach(Template::fairing())
.launch()
.await?;
Ok(())
}

@ -0,0 +1 @@
&copy; Local Driver Technologies, Inc.

@ -0,0 +1,3 @@
<nav>
<a href="/">Home</a>
</nav>

@ -0,0 +1,9 @@
{% extends "master" %}
{% block content %}
<h1>Hello world, {{ name }}</h1>
<ul>
{% for n in note %}
<li>{{ n.title }}</li>
{% endfor %}
</ul>
{% endblock %}

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ title }} | example.org</title>
</head>
<body>
<header>
{% include "header" %}
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer>
{% include "footer" %}
</footer>
</body>
</html>
Loading…
Cancel
Save