1
0
mirror of https://github.com/actix/actix-website synced 2025-02-02 04:09:06 +01:00

Fixed indentation on frontpage

This commit is contained in:
Armin Ronacher 2018-06-24 21:57:20 +02:00
parent 83556270bc
commit 513ef13784

View File

@ -40,23 +40,23 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="actix-content"> <div class="actix-content">
{{ highlight `extern crate actix_web; {{ 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 { fn greet(req: HttpRequest) -> impl Responder {
let to = req.match_info().get("name").unwrap_or("World"); let to = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", to) format!("Hello {}!", to)
} }
fn main() { fn main() {
server::new(|| { server::new(|| {
App::new() App::new()
.resource("/", |r| r.f(greet)) .resource("/", |r| r.f(greet))
.resource("/{name}", |r| r.f(greet)) .resource("/{name}", |r| r.f(greet))
}) })
.bind("127.0.0.1:8000") .bind("127.0.0.1:8000")
.expect("Can not bind to port 8000") .expect("Can not bind to port 8000")
.run(); .run();
}` "rust" "" }} }` "rust" "" }}
</div> </div>
</div> </div>
</div> </div>
@ -70,17 +70,17 @@
to return consistent responses from your APIs. to return consistent responses from your APIs.
</p> </p>
{{ highlight `#[derive(Serialize)] {{ highlight `#[derive(Serialize)]
struct Measurement { struct Measurement {
temperature: f32, temperature: f32,
} }
fn hello_world() -> impl Responder { fn hello_world() -> impl Responder {
"Hello World!" "Hello World!"
} }
fn current_temperature(_req: HttpRequest) -> impl Responder { fn current_temperature(_req: HttpRequest) -> impl Responder {
Json(Measurement { temperature: 42.3 }) Json(Measurement { temperature: 42.3 })
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div class="actix-feature" id="extractors"> <div class="actix-feature" id="extractors">
<h2>Powerful Extractors</h2> <h2>Powerful Extractors</h2>
@ -92,16 +92,16 @@
from asynchronous IO handling. from asynchronous IO handling.
</p> </p>
{{ highlight `#[derive(Deserialize)] {{ highlight `#[derive(Deserialize)]
struct Event { struct Event {
timestamp: f64, timestamp: f64,
kind: String, kind: String,
tags: Vec<String>, tags: Vec<String>,
} }
fn capture_event(evt: Json<Event>) -> impl Responder { fn capture_event(evt: Json<Event>) -> impl Responder {
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags); let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
format!("got event {}", id) format!("got event {}", id)
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div class="actix-feature" id="forms"> <div class="actix-feature" id="forms">
<h2>Easy Form Handling</h2> <h2>Easy Form Handling</h2>
@ -111,14 +111,14 @@
the rest. the rest.
</p> </p>
{{ highlight `#[derive(Deserialize)] {{ highlight `#[derive(Deserialize)]
struct Register { struct Register {
username: String, username: String,
country: String, country: String,
} }
fn register(data: Form<Register>) -> impl Responder { fn register(data: Form<Register>) -> impl Responder {
format!("Hello {} from {}!", data.username, data.country) format!("Hello {} from {}!", data.username, data.country)
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div class="actix-feature" id="routing"> <div class="actix-feature" id="routing">
<h2>Request Routing</h2> <h2>Request Routing</h2>
@ -128,19 +128,19 @@
can be used. can be used.
</p> </p>
{{ highlight `fn index(req: HttpRequest) -> impl Responder { {{ highlight `fn index(req: HttpRequest) -> impl Responder {
"Hello from the index page" "Hello from the index page"
} }
fn hello(path: Path<String>) -> impl Responder { fn hello(path: Path<String>) -> impl Responder {
format!("Hello {}!", *path) format!("Hello {}!", *path)
} }
fn main() { fn main() {
App::new() App::new()
.resource("/", |r| r.method(Method::Get).with(index)) .resource("/", |r| r.method(Method::Get).with(index))
.resource("/hello/{name}", |r| r.method(Method::Get).with(hello)) .resource("/hello/{name}", |r| r.method(Method::Get).with(hello))
.finish(); .finish();
}` "rust" "" }} }` "rust" "" }}
</div> </div>
</div> </div>
<div class="col-md-3 actix-feature-selectors"> <div class="col-md-3 actix-feature-selectors">
@ -195,19 +195,19 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="actix-content"> <div class="actix-content">
{{ highlight `extern crate actix_web; {{ highlight `extern crate actix_web;
use actix_web::{http::Method, server, App, Path, Responder}; use actix_web::{http::Method, server, App, Path, Responder};
fn index(info: Path<(u32, String)>) -> impl Responder { fn index(info: Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0) format!("Hello {}! id:{}", info.1, info.0)
} }
fn main() { fn main() {
server::new( server::new(
|| App::new() || App::new()
.route("/{id}/{name}/index.html", Method::GET, index)) .route("/{id}/{name}/index.html", Method::GET, index))
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.run(); .run();
}` "rust" "" }} }` "rust" "" }}
</div> </div>
</div> </div>
</div> </div>
@ -222,17 +222,17 @@
Actix中的Handler函数可以返回实现该<code>Respondert</code> rait的各种对象。这使得从API返回一致的响应变得轻而易举。 Actix中的Handler函数可以返回实现该<code>Respondert</code> rait的各种对象。这使得从API返回一致的响应变得轻而易举。
</p> </p>
{{ highlight `#[derive(Serialize)] {{ highlight `#[derive(Serialize)]
struct Measurement { struct Measurement {
temperature: f32, temperature: f32,
} }
fn hello_world() -> impl Responder { fn hello_world() -> impl Responder {
"Hello World!" "Hello World!"
} }
fn current_temperature(_req: HttpRequest) -> impl Responder { fn current_temperature(_req: HttpRequest) -> impl Responder {
Json(Measurement { temperature: 42.3 }) Json(Measurement { temperature: 42.3 })
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div id="con_one_2" style="display:none;"> <div id="con_one_2" style="display:none;">
<h2>强大的Extractors</h2> <h2>强大的Extractors</h2>
@ -241,16 +241,16 @@
而且还意味着您的视图函数可以是同步代码并且仍然可以受益于异步IO处理。 而且还意味着您的视图函数可以是同步代码并且仍然可以受益于异步IO处理。
</p> </p>
{{ highlight `#[derive(Deserialize)] {{ highlight `#[derive(Deserialize)]
struct Event { struct Event {
timestamp: f64, timestamp: f64,
kind: String, kind: String,
tags: Vec<String>, tags: Vec<String>,
} }
fn capture_event(evt: Json<Event>) -> impl Responder { fn capture_event(evt: Json<Event>) -> impl Responder {
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags); let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
format!("got event {}", id) format!("got event {}", id)
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div id="con_one_3" style="display:none;"> <div id="con_one_3" style="display:none;">
<h2>轻松处理表单</h2> <h2>轻松处理表单</h2>
@ -258,14 +258,14 @@
处理multipart/ urlencoded表单数据很容易。只需定义一个可以反序列化的结构actix就可以处理剩下的部分。 处理multipart/ urlencoded表单数据很容易。只需定义一个可以反序列化的结构actix就可以处理剩下的部分。
</p> </p>
{{ highlight `#[derive(Deserialize)] {{ highlight `#[derive(Deserialize)]
struct Register { struct Register {
username: String, username: String,
country: String, country: String,
} }
fn register(data: Form<Register>) -> impl Responder { fn register(data: Form<Register>) -> impl Responder {
format!("Hello {} from {}!", data.username, data.country) format!("Hello {} from {}!", data.username, data.country)
}` "rust" "" }} }` "rust" "" }}
</div> </div>
<div id="con_one_4" style="display:none;"> <div id="con_one_4" style="display:none;">
<h2>请求路由</h2> <h2>请求路由</h2>
@ -273,19 +273,19 @@
一个actix应用程序带有一个URL路由系统可以让你在URL上匹配并调用单个处理程序。为了获得额外的灵活性可以使用域。 一个actix应用程序带有一个URL路由系统可以让你在URL上匹配并调用单个处理程序。为了获得额外的灵活性可以使用域。
</p> </p>
{{ highlight `fn index(req: HttpRequest) -> impl Responder { {{ highlight `fn index(req: HttpRequest) -> impl Responder {
"Hello from the index page" "Hello from the index page"
} }
fn hello(path: Path<String>) -> impl Responder { fn hello(path: Path<String>) -> impl Responder {
format!("Hello {}!", *path) format!("Hello {}!", *path)
} }
fn main() { fn main() {
App::new() App::new()
.resource("/", |r| r.method(Method::Get).with(index)) .resource("/", |r| r.method(Method::Get).with(index))
.resource("/hello/{name}", |r| r.method(Method::Get).with(hello)) .resource("/hello/{name}", |r| r.method(Method::Get).with(hello))
.finish(); .finish();
}` "rust" "" }} }` "rust" "" }}
</div> </div>
</div> </div>