From 513ef1378428f90ec715d46a6f8ac14472797965 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 24 Jun 2018 21:57:20 +0200 Subject: [PATCH] Fixed indentation on frontpage --- layouts/index.html | 212 ++++++++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/layouts/index.html b/layouts/index.html index 31889eb..90f6ed0 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -40,23 +40,23 @@
{{ highlight `extern crate actix_web; - use actix_web::{server, App, HttpRequest, Responder}; +use actix_web::{server, App, HttpRequest, Responder}; - fn greet(req: HttpRequest) -> impl Responder { - let to = req.match_info().get("name").unwrap_or("World"); - format!("Hello {}!", to) - } +fn greet(req: HttpRequest) -> impl Responder { + let to = req.match_info().get("name").unwrap_or("World"); + format!("Hello {}!", to) +} - fn main() { - server::new(|| { - App::new() - .resource("/", |r| r.f(greet)) - .resource("/{name}", |r| r.f(greet)) - }) - .bind("127.0.0.1:8000") - .expect("Can not bind to port 8000") - .run(); - }` "rust" "" }} +fn main() { + server::new(|| { + App::new() + .resource("/", |r| r.f(greet)) + .resource("/{name}", |r| r.f(greet)) + }) + .bind("127.0.0.1:8000") + .expect("Can not bind to port 8000") + .run(); +}` "rust" "" }}
@@ -70,17 +70,17 @@ to return consistent responses from your APIs.

{{ highlight `#[derive(Serialize)] - struct Measurement { - temperature: f32, - } +struct Measurement { + temperature: f32, +} - fn hello_world() -> impl Responder { - "Hello World!" - } +fn hello_world() -> impl Responder { + "Hello World!" +} - fn current_temperature(_req: HttpRequest) -> impl Responder { - Json(Measurement { temperature: 42.3 }) - }` "rust" "" }} +fn current_temperature(_req: HttpRequest) -> impl Responder { + Json(Measurement { temperature: 42.3 }) +}` "rust" "" }}

Powerful Extractors

@@ -92,16 +92,16 @@ from asynchronous IO handling.

{{ highlight `#[derive(Deserialize)] - struct Event { - timestamp: f64, - kind: String, - tags: Vec, - } +struct Event { + timestamp: f64, + kind: String, + tags: Vec, +} - fn capture_event(evt: Json) -> impl Responder { - let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags); - format!("got event {}", id) - }` "rust" "" }} +fn capture_event(evt: Json) -> impl Responder { + let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags); + format!("got event {}", id) +}` "rust" "" }}

Easy Form Handling

@@ -111,14 +111,14 @@ the rest.

{{ highlight `#[derive(Deserialize)] - struct Register { - username: String, - country: String, - } +struct Register { + username: String, + country: String, +} - fn register(data: Form) -> impl Responder { - format!("Hello {} from {}!", data.username, data.country) - }` "rust" "" }} +fn register(data: Form) -> impl Responder { + format!("Hello {} from {}!", data.username, data.country) +}` "rust" "" }}

Request Routing

@@ -128,19 +128,19 @@ can be used.

{{ highlight `fn index(req: HttpRequest) -> impl Responder { - "Hello from the index page" - } + "Hello from the index page" +} - fn hello(path: Path) -> impl Responder { - format!("Hello {}!", *path) - } +fn hello(path: Path) -> impl Responder { + format!("Hello {}!", *path) +} - fn main() { - App::new() - .resource("/", |r| r.method(Method::Get).with(index)) - .resource("/hello/{name}", |r| r.method(Method::Get).with(hello)) - .finish(); - }` "rust" "" }} +fn main() { + App::new() + .resource("/", |r| r.method(Method::Get).with(index)) + .resource("/hello/{name}", |r| r.method(Method::Get).with(hello)) + .finish(); +}` "rust" "" }}
@@ -195,19 +195,19 @@
{{ highlight `extern crate actix_web; - use actix_web::{http::Method, server, App, Path, Responder}; - - fn index(info: Path<(u32, String)>) -> impl Responder { - format!("Hello {}! id:{}", info.1, info.0) - } - - fn main() { - server::new( - || App::new() - .route("/{id}/{name}/index.html", Method::GET, index)) - .bind("127.0.0.1:8080").unwrap() - .run(); - }` "rust" "" }} +use actix_web::{http::Method, server, App, Path, Responder}; + +fn index(info: Path<(u32, String)>) -> impl Responder { + format!("Hello {}! id:{}", info.1, info.0) +} + +fn main() { + server::new( + || App::new() + .route("/{id}/{name}/index.html", Method::GET, index)) + .bind("127.0.0.1:8080").unwrap() + .run(); +}` "rust" "" }}
@@ -222,17 +222,17 @@ Actix中的Handler函数可以返回实现该Respondert rait的各种对象。这使得从API返回一致的响应变得轻而易举。

{{ highlight `#[derive(Serialize)] - struct Measurement { - temperature: f32, - } - - fn hello_world() -> impl Responder { - "Hello World!" - } - - fn current_temperature(_req: HttpRequest) -> impl Responder { - Json(Measurement { temperature: 42.3 }) - }` "rust" "" }} + struct Measurement { + temperature: f32, +} + +fn hello_world() -> impl Responder { + "Hello World!" +} + +fn current_temperature(_req: HttpRequest) -> impl Responder { + Json(Measurement { temperature: 42.3 }) +}` "rust" "" }}