Skip to content

Instantly share code, notes, and snippets.

@mhutter
Created May 22, 2021 18:43
Show Gist options
  • Save mhutter/98d77c21ad352cdaa92039bd6e3981a8 to your computer and use it in GitHub Desktop.
Save mhutter/98d77c21ad352cdaa92039bd6e3981a8 to your computer and use it in GitHub Desktop.
Rust Rocket examples
#![feature(proc_macro_hygiene, decl_macro)]
use rocket::State;
#[macro_use]
extern crate rocket;
struct ExampleA(&'static str);
type ExampleB = &'static str;
#[get("/a")]
fn a(a: State<ExampleA>) -> &'static str {
a.0
}
#[get("/b")]
fn b(b: State<ExampleB>) -> &'static str {
b.inner()
}
fn main() {
rocket::ignite()
.mount("/", routes![a, b])
.manage(ExampleA("some config"))
.manage("v1.3.37" as ExampleB)
.launch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment