mirror of
https://github.com/actix/actix-website
synced 2025-06-29 08:14:58 +02:00
Merge pull request #90 from cldershem/update1.0
[WIP] Update website docs to 1.0.
This commit is contained in:
@ -79,7 +79,7 @@
|
||||
<div>
|
||||
<ul class="nav">
|
||||
<li><a href="https://docs.rs/actix" target="view_window">actix <span class="fa fa-external-link"></span></a></li>
|
||||
<li><a href="https://actix.rs/api/actix-web/stable/actix_web/" target="view_window">actix-web <span class="fa fa-external-link"></span></a></li>
|
||||
<li><a href="https://docs.rs/actix-web/" target="view_window">actix-web <span class="fa fa-external-link"></span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -22,7 +22,7 @@
|
||||
<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>
|
||||
<p>Actix provides a lot of features out of box. HTTP/2, logging, etc.</p>
|
||||
|
||||
<h2>
|
||||
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
|
||||
@ -39,23 +39,23 @@
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="actix-content">
|
||||
{{ highlight `extern crate actix_web;
|
||||
use actix_web::{server, App, HttpRequest, Responder};
|
||||
{{ highlight `use actix_web::{web, App, HttpRequest, HttpServer};
|
||||
|
||||
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 name = req.match_info().get("name").unwrap_or("World");
|
||||
format!("Hello {}!", &name)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
server::new(|| {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.resource("/", |r| r.f(greet))
|
||||
.resource("/{name}", |r| r.f(greet))
|
||||
.route("/", web::get().to(greet))
|
||||
.route("/{name}", web::get().to(greet))
|
||||
})
|
||||
.bind("127.0.0.1:8000")
|
||||
.expect("Can not bind to port 8000")
|
||||
.run();
|
||||
.run()
|
||||
.unwrap();
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
</div>
|
||||
@ -78,8 +78,8 @@ fn hello_world() -> impl Responder {
|
||||
"Hello World!"
|
||||
}
|
||||
|
||||
fn current_temperature(_req: HttpRequest) -> impl Responder {
|
||||
Json(Measurement { temperature: 42.3 })
|
||||
fn current_temperature() -> impl Responder {
|
||||
web::Json(Measurement { temperature: 42.3 })
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
<div class="actix-feature" id="extractors">
|
||||
@ -91,16 +91,17 @@ fn current_temperature(_req: HttpRequest) -> impl Responder {
|
||||
your view functions can be synchronous code and still benefit
|
||||
from asynchronous IO handling.
|
||||
</p>
|
||||
{{ highlight `#[derive(Deserialize)]
|
||||
{{ highlight `#[derive(Deserialize, Serialize)]
|
||||
struct Event {
|
||||
id: Option<i32>,
|
||||
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)
|
||||
fn capture_event(evt: web::Json<Event>) -> impl Responder {
|
||||
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags);
|
||||
format!("got event {}", new_event.id.unwrap())
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
<div class="actix-feature" id="forms">
|
||||
@ -116,8 +117,8 @@ struct Register {
|
||||
country: String,
|
||||
}
|
||||
|
||||
fn register(data: Form<Register>) -> impl Responder {
|
||||
format!("Hello {} from {}!", data.username, data.country)
|
||||
fn register(form: web::Form<Register>) -> impl Responder {
|
||||
format!("Hello {} from {}!", form.username, form.country)
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
<div class="actix-feature" id="routing">
|
||||
@ -127,19 +128,18 @@ fn register(data: Form<Register>) -> impl Responder {
|
||||
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"
|
||||
{{ highlight `fn index(_req: HttpRequest) -> impl Responder {
|
||||
"Hello from the index page!"
|
||||
}
|
||||
|
||||
fn hello(path: Path<String>) -> impl Responder {
|
||||
format!("Hello {}!", *path)
|
||||
fn hello(path: web::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();
|
||||
.route("/", web::get().to(index))
|
||||
.route("/{name}", web::get().to(hello));
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
</div>
|
||||
|
5
layouts/shortcodes/rust-version.html
Normal file
5
layouts/shortcodes/rust-version.html
Normal file
@ -0,0 +1,5 @@
|
||||
{{- if eq (.Get 0) "actix" -}}
|
||||
{{- .Page.Site.Params.actixMinRustVersion -}}
|
||||
{{- else if eq (.Get 0) "actix-web" -}}
|
||||
{{- .Page.Site.Params.actixWebMinRustVersion -}}
|
||||
{{- end -}}
|
Reference in New Issue
Block a user