mirror of
https://github.com/actix/actix-website
synced 2025-01-23 00:25:55 +01:00
cn home page for cn
This commit is contained in:
parent
b53596e1b6
commit
4349263ff5
@ -1,3 +1,3 @@
|
|||||||
---
|
---
|
||||||
title: Actix中文社区
|
title: Actix中文
|
||||||
---
|
---
|
||||||
|
@ -1,154 +1,298 @@
|
|||||||
{{ partial "header" . }}
|
{{ partial "header" . }}
|
||||||
|
|
||||||
<div class="jumbotron">
|
<div id="act-home-cn">
|
||||||
<div class="actix-jumbotron">
|
<div class="jumbotron">
|
||||||
<img src="/img/logo-large.png" class="align-middle actix-logo" alt="">
|
<div class="actix-jumbotron">
|
||||||
<p class="lead">rust's powerful actor system and most fun web framework</p>
|
<img src="/img/logo-large.png" class="align-middle actix-logo" alt="">
|
||||||
</div>
|
<p class="lead">Rust的actor系统和有趣的web框架</p>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="container actix-home">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="actix-features">
|
|
||||||
<h2>
|
|
||||||
<i class="fa fa-fw fa-shield" aria-hidden="true"></i>
|
|
||||||
Type Safe
|
|
||||||
</h2>
|
|
||||||
<p>Forget about stringly typed objects, from request to response, everything has types.</p>
|
|
||||||
|
|
||||||
<h2>
|
|
||||||
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
|
|
||||||
Feature Rich
|
|
||||||
</h2>
|
|
||||||
<p>Actix provides a lot of features out of box. WebSockets, HTTP/2, pipelining etc.</p>
|
|
||||||
|
|
||||||
<h2>
|
|
||||||
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
|
|
||||||
Extensible
|
|
||||||
</h2>
|
|
||||||
<p>Easily create your own libraries that any Actix application can use.</p>
|
|
||||||
|
|
||||||
<h2>
|
|
||||||
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
|
|
||||||
Blazingly Fast
|
|
||||||
</h2>
|
|
||||||
<p>Actix is blazingly fast. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">Check yourself</a>.</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-8">
|
|
||||||
<div class="actix-content">
|
<div class="container actix-home">
|
||||||
{{ highlight `extern crate actix_web;
|
<div class="row">
|
||||||
use actix_web::{server, App, HttpRequest, Responder};
|
<div class="col-md-4">
|
||||||
|
<div class="actix-features">
|
||||||
fn greet(req: HttpRequest) -> impl Responder {
|
<h2>
|
||||||
let to = req.match_info().get("name").unwrap_or("World");
|
<i class="fa fa-fw fa-shield" aria-hidden="true"></i>
|
||||||
format!("Hello {}!", to)
|
类型安全
|
||||||
}
|
</h2>
|
||||||
|
<p>忘记关于字符串类型的对象,从请求到响应,一切都有类型,异步。</p>
|
||||||
fn main() {
|
|
||||||
server::new(|| {
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
|
||||||
|
特性丰富
|
||||||
|
</h2>
|
||||||
|
<p>Actix提供了丰富的特性开箱即用。WebSockets,HTTP/2,流,管道,SSL,异步HTTTP客户端等一应俱全.</p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
|
||||||
|
扩展性强
|
||||||
|
</h2>
|
||||||
|
<p>轻松创建任何基于Actix应用的自己的特色库。</p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
|
||||||
|
速度极快
|
||||||
|
</h2>
|
||||||
|
<p>Actix 具有顶级的速度. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">Check yourself</a>.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="actix-content">
|
||||||
|
{{ 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" "" }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="actix-showcase">
|
||||||
|
<div class="col-md-9">
|
||||||
|
<div class="actix-feature" id="responders">
|
||||||
|
<h2>灵活的请求响应</h2>
|
||||||
|
<p>
|
||||||
|
Actix中的Handler函数可以返回实现该Respondert rait的各种对象。这使得从API返回一致的响应变得轻而易举。
|
||||||
|
</p>
|
||||||
|
{{ 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" "" }}
|
||||||
|
</div>
|
||||||
|
<div class="actix-feature" id="extractors">
|
||||||
|
<h2>强大的Extractors</h2>
|
||||||
|
<p>
|
||||||
|
Actix提供了一个强大的提取器系统,可以从传入的HTTP请求中提取数据并将其传递给您的视图函数。这不仅可以创建方便的API,
|
||||||
|
而且还意味着您的视图函数可以是同步代码,并且仍然可以受益于异步IO处理。
|
||||||
|
</p>
|
||||||
|
{{ highlight `#[derive(Deserialize)]
|
||||||
|
struct Event {
|
||||||
|
timestamp: f64,
|
||||||
|
kind: String,
|
||||||
|
tags: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn capture_event(evt: Json<Event>) -> impl Responder {
|
||||||
|
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
|
||||||
|
format!("got event {}", id)
|
||||||
|
}` "rust" "" }}
|
||||||
|
</div>
|
||||||
|
<div class="actix-feature" id="forms">
|
||||||
|
<h2>轻松处理表单</h2>
|
||||||
|
<p>
|
||||||
|
处理multipart/ urlencoded表单数据很容易。只需定义一个可以反序列化的结构,actix就可以处理剩下的部分。
|
||||||
|
</p>
|
||||||
|
{{ highlight `#[derive(Deserialize)]
|
||||||
|
struct Register {
|
||||||
|
username: String,
|
||||||
|
country: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register(data: Form<Register>) -> impl Responder {
|
||||||
|
format!("Hello {} from {}!", data.username, data.country)
|
||||||
|
}` "rust" "" }}
|
||||||
|
</div>
|
||||||
|
<div class="actix-feature" id="routing">
|
||||||
|
<h2>请求路由</h2>
|
||||||
|
<p>
|
||||||
|
一个actix应用程序带有一个URL路由系统,可以让你在URL上匹配并调用单个处理程序。为了获得额外的灵活性,可以使用域。
|
||||||
|
</p>
|
||||||
|
{{ highlight `fn index(req: HttpRequest) -> impl Responder {
|
||||||
|
"Hello from the index page"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hello(path: Path<String>) -> impl Responder {
|
||||||
|
format!("Hello {}!", *path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.resource("/", |r| r.f(greet))
|
.resource("/", |r| r.method(Method::Get).with(index))
|
||||||
.resource("/{name}", |r| r.f(greet))
|
.resource("/hello/{name}", |r| r.method(Method::Get).with(hello))
|
||||||
})
|
.finish();
|
||||||
.bind("127.0.0.1:8000")
|
}` "rust" "" }}
|
||||||
.expect("Can not bind to port 8000")
|
</div>
|
||||||
.run();
|
</div>
|
||||||
}` "rust" "" }}
|
<div class="col-md-3 actix-feature-selectors">
|
||||||
|
<ul>
|
||||||
|
<li class="actix-feature-selector"><a href="#responders">灵活的请求响应</label>
|
||||||
|
<li class="actix-feature-selector"><a href="#extractors">强大的Extractors</label>
|
||||||
|
<li class="actix-feature-selector"><a href="#forms">轻松处理表单</label>
|
||||||
|
<li class="actix-feature-selector"><a href="#routing">请求路由</label>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="actix-showcase">
|
|
||||||
<div class="col-md-9">
|
|
||||||
<div class="actix-feature" id="responders">
|
|
||||||
<h2>Flexible Responders</h2>
|
|
||||||
<p>
|
|
||||||
Handler functions in actix can return a wide range of objects that
|
|
||||||
implement the <code>Responder</code> trait. This makes it a breeze
|
|
||||||
to return consistent responses from your APIs.
|
|
||||||
</p>
|
|
||||||
{{ highlight `#[derive(Serialize)]
|
|
||||||
struct Measurement {
|
|
||||||
temperature: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hello_world() -> impl Responder {
|
<div id="act-home">
|
||||||
"Hello World!"
|
<div class="jumbotron">
|
||||||
}
|
<div class="actix-jumbotron">
|
||||||
|
<img src="/img/logo-large.png" class="align-middle actix-logo" alt="">
|
||||||
|
<p class="lead">rust's powerful actor system and most fun web framework</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
fn current_temperature(_req: HttpRequest) -> impl Responder {
|
<div class="container actix-home">
|
||||||
Json(Measurement { temperature: 42.3 })
|
<div class="row">
|
||||||
}` "rust" "" }}
|
<div class="col-md-4">
|
||||||
|
<div class="actix-features">
|
||||||
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-shield" aria-hidden="true"></i>
|
||||||
|
Type Safe
|
||||||
|
</h2>
|
||||||
|
<p>Forget about stringly typed objects, from request to response, everything has types.</p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
|
||||||
|
Feature Rich
|
||||||
|
</h2>
|
||||||
|
<p>Actix provides a lot of features out of box. WebSockets, HTTP/2, pipelining etc.</p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
|
||||||
|
Extensible
|
||||||
|
</h2>
|
||||||
|
<p>Easily create your own libraries that any Actix application can use.</p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
|
||||||
|
Blazingly Fast
|
||||||
|
</h2>
|
||||||
|
<p>Actix is blazingly fast. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">Check yourself</a>.</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="actix-feature" id="extractors">
|
<div class="col-md-8">
|
||||||
<h2>Powerful Extractors</h2>
|
<div class="actix-content">
|
||||||
<p>
|
{{ highlight `extern crate actix_web;
|
||||||
Actix comes with a powerful extractor system that extracts data
|
use actix_web::{server, App, HttpRequest, Responder};
|
||||||
from the incoming HTTP request and passes it to your view functions.
|
|
||||||
Not only does this make for a convenient API but it also means that
|
|
||||||
your view functions can be synchronous code and still benefit
|
|
||||||
from asynchronous IO handling.
|
|
||||||
</p>
|
|
||||||
{{ highlight `#[derive(Deserialize)]
|
|
||||||
struct Event {
|
|
||||||
timestamp: f64,
|
|
||||||
kind: String,
|
|
||||||
tags: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn capture_event(evt: Json<Event>) -> impl Responder {
|
fn greet(req: HttpRequest) -> impl Responder {
|
||||||
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
|
let to = req.match_info().get("name").unwrap_or("World");
|
||||||
format!("got event {}", id)
|
format!("Hello {}!", to)
|
||||||
}` "rust" "" }}
|
}
|
||||||
</div>
|
|
||||||
<div class="actix-feature" id="forms">
|
|
||||||
<h2>Easy Form Handling</h2>
|
|
||||||
<p>
|
|
||||||
Handling multipart/urlencoded form data is easy. Just define
|
|
||||||
a structure that can be deserialized and actix will handle
|
|
||||||
the rest.
|
|
||||||
</p>
|
|
||||||
{{ highlight `#[derive(Deserialize)]
|
|
||||||
struct Register {
|
|
||||||
username: String,
|
|
||||||
country: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register(data: Form<Register>) -> impl Responder {
|
fn main() {
|
||||||
format!("Hello {} from {}!", data.username, data.country)
|
server::new(|| {
|
||||||
}` "rust" "" }}
|
App::new()
|
||||||
</div>
|
.resource("/", |r| r.f(greet))
|
||||||
<div class="actix-feature" id="routing">
|
.resource("/{name}", |r| r.f(greet))
|
||||||
<h2>Request Routing</h2>
|
})
|
||||||
<p>
|
.bind("127.0.0.1:8000")
|
||||||
An actix app comes with a URL routing system that lets you match on
|
.expect("Can not bind to port 8000")
|
||||||
URLs and invoke individual handlers. For extra flexibility, scopes
|
.run();
|
||||||
can be used.
|
}` "rust" "" }}
|
||||||
</p>
|
</div>
|
||||||
{{ highlight `fn index(req: HttpRequest) -> impl Responder {
|
|
||||||
"Hello from the index page"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hello(path: Path<String>) -> 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" "" }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3 actix-feature-selectors">
|
<div class="actix-showcase">
|
||||||
<ul>
|
<div class="col-md-9">
|
||||||
<li class="actix-feature-selector"><a href="#responders">flexible responders</label>
|
<div class="actix-feature" id="responders">
|
||||||
<li class="actix-feature-selector"><a href="#extractors">powerful extractors</label>
|
<h2>Flexible Responders</h2>
|
||||||
<li class="actix-feature-selector"><a href="#forms">easy form handling</label>
|
<p>
|
||||||
<li class="actix-feature-selector"><a href="#routing">request routing</label>
|
Handler functions in actix can return a wide range of objects that
|
||||||
</ul>
|
implement the <code>Responder</code> trait. This makes it a breeze
|
||||||
|
to return consistent responses from your APIs.
|
||||||
|
</p>
|
||||||
|
{{ 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" "" }}
|
||||||
|
</div>
|
||||||
|
<div class="actix-feature" id="extractors">
|
||||||
|
<h2>Powerful Extractors</h2>
|
||||||
|
<p>
|
||||||
|
Actix comes with a powerful extractor system that extracts data
|
||||||
|
from the incoming HTTP request and passes it to your view functions.
|
||||||
|
Not only does this make for a convenient API but it also means that
|
||||||
|
your view functions can be synchronous code and still benefit
|
||||||
|
from asynchronous IO handling.
|
||||||
|
</p>
|
||||||
|
{{ highlight `#[derive(Deserialize)]
|
||||||
|
struct Event {
|
||||||
|
timestamp: f64,
|
||||||
|
kind: String,
|
||||||
|
tags: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn capture_event(evt: Json<Event>) -> impl Responder {
|
||||||
|
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
|
||||||
|
format!("got event {}", id)
|
||||||
|
}` "rust" "" }}
|
||||||
|
</div>
|
||||||
|
<div class="actix-feature" id="forms">
|
||||||
|
<h2>Easy Form Handling</h2>
|
||||||
|
<p>
|
||||||
|
Handling multipart/urlencoded form data is easy. Just define
|
||||||
|
a structure that can be deserialized and actix will handle
|
||||||
|
the rest.
|
||||||
|
</p>
|
||||||
|
{{ highlight `#[derive(Deserialize)]
|
||||||
|
struct Register {
|
||||||
|
username: String,
|
||||||
|
country: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register(data: Form<Register>) -> impl Responder {
|
||||||
|
format!("Hello {} from {}!", data.username, data.country)
|
||||||
|
}` "rust" "" }}
|
||||||
|
</div>
|
||||||
|
<div class="actix-feature" id="routing">
|
||||||
|
<h2>Request Routing</h2>
|
||||||
|
<p>
|
||||||
|
An actix app comes with a URL routing system that lets you match on
|
||||||
|
URLs and invoke individual handlers. For extra flexibility, scopes
|
||||||
|
can be used.
|
||||||
|
</p>
|
||||||
|
{{ highlight `fn index(req: HttpRequest) -> impl Responder {
|
||||||
|
"Hello from the index page"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hello(path: Path<String>) -> 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" "" }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 actix-feature-selectors">
|
||||||
|
<ul>
|
||||||
|
<li class="actix-feature-selector"><a href="#responders">flexible responders</label>
|
||||||
|
<li class="actix-feature-selector"><a href="#extractors">powerful extractors</label>
|
||||||
|
<li class="actix-feature-selector"><a href="#forms">easy form handling</label>
|
||||||
|
<li class="actix-feature-selector"><a href="#routing">request routing</label>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,5 +15,18 @@
|
|||||||
<script src="/js/bootstrap.min.js"></script>
|
<script src="/js/bootstrap.min.js"></script>
|
||||||
<script src="/js/actix.js"></script>
|
<script src="/js/actix.js"></script>
|
||||||
{{ template "_internal/google_analytics.html" . }}
|
{{ template "_internal/google_analytics.html" . }}
|
||||||
|
|
||||||
|
<script type="text/javascript" async>
|
||||||
|
window.onload = function(){
|
||||||
|
if (window.location.href.indexOf("https://actix.rs/cn/") == 0) {
|
||||||
|
var actix_home = document.getElementById("act-home")
|
||||||
|
actix_home.style.display = "none"
|
||||||
|
}
|
||||||
|
if (window.location.href.indexOf("https://actix.rs/") == 0) {
|
||||||
|
var actix_home_cn = document.getElementById("act-home-cn")
|
||||||
|
actix_home_cn.style.display = "none"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user