mirror of
https://github.com/actix/actix-website
synced 2024-11-27 18:12:57 +01:00
Front page examples return 'impl Responder'
This commit is contained in:
parent
f922e8fb96
commit
3f95205696
@ -1,5 +1,5 @@
|
||||
// <easy-form-handling>
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -14,11 +14,8 @@ fn index() -> HttpResponse {
|
||||
.body(include_str!("../static/form.html"))
|
||||
}
|
||||
|
||||
fn register(params: web::Form<Register>) -> actix_web::Result<HttpResponse> {
|
||||
Ok(HttpResponse::Ok().body(format!(
|
||||
"Hello {} from {}!",
|
||||
params.username, params.country
|
||||
)))
|
||||
fn register(params: web::Form<Register>) -> impl Responder {
|
||||
format!("Hello {} from {}!", params.username, params.country)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,9 +1,9 @@
|
||||
// <main-example>
|
||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
|
||||
fn greet(req: HttpRequest) -> HttpResponse {
|
||||
fn greet(req: HttpRequest) -> impl Responder {
|
||||
let name = req.match_info().get("name").unwrap_or("World");
|
||||
HttpResponse::Ok().body(format!("Hello {}!", &name))
|
||||
format!("Hello {}!", &name)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
@ -20,9 +20,9 @@ fn store_event_in_db(timestamp: f64, kind: String, tags: Vec<String>) -> Event {
|
||||
}
|
||||
}
|
||||
|
||||
fn capture_event(evt: web::Json<Event>) -> actix_web::Result<HttpResponse> {
|
||||
fn capture_event(evt: web::Json<Event>) -> impl Responder {
|
||||
let new_event = store_event_in_db(evt.timestamp, evt.kind.clone(), evt.tags.clone());
|
||||
Ok(HttpResponse::Ok().json(new_event))
|
||||
format!("got event {}", new_event.id.unwrap())
|
||||
}
|
||||
|
||||
fn index() -> HttpResponse {
|
||||
|
@ -1,12 +1,12 @@
|
||||
// <request-routing>
|
||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok().body("Hello from the index page.")
|
||||
fn index(_req: HttpRequest) -> impl Responder {
|
||||
"Hello from the index page."
|
||||
}
|
||||
|
||||
fn hello(path: web::Path<String>) -> HttpResponse {
|
||||
HttpResponse::Ok().body(format!("Hello {}!", &path))
|
||||
fn hello(path: web::Path<String>) -> impl Responder {
|
||||
format!("Hello {}!", &path)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -41,9 +41,9 @@
|
||||
<div class="actix-content">
|
||||
{{ highlight `use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
|
||||
fn greet(req: HttpRequest) -> HttpResponse {
|
||||
fn greet(req: HttpRequest) -> impl Responder {
|
||||
let name = req.match_info().get("name").unwrap_or("World");
|
||||
HttpResponse::Ok().body(format!("Hello {}!", &name))
|
||||
format!("Hello {}!", &name)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -98,11 +98,11 @@ struct Event {
|
||||
kind: String,
|
||||
tags: Vec<String>,
|
||||
}
|
||||
fn capture_event(evt: web::Json<Event>) -> actix_web::Result<HttpResponse> {
|
||||
fn capture_event(evt: web::Json<Event>) -> impl Responder {
|
||||
let new_event = store_event_in_db(evt.timestamp,
|
||||
evt.kind.clone(),
|
||||
evt.tags.clone());
|
||||
Ok(HttpResponse::Ok().json(new_event))
|
||||
format!("got event {}", new_event.id.unwrap())
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
<div class="actix-feature" id="forms">
|
||||
@ -118,11 +118,8 @@ struct Register {
|
||||
country: String,
|
||||
}
|
||||
|
||||
fn register(params: web::Form<Register>) -> actix_web::Result<HttpResponse> {
|
||||
Ok(HttpResponse::Ok().body(format!(
|
||||
"Hello {} from {}!",
|
||||
params.username, params.country
|
||||
)))
|
||||
fn register(params: web::Form<Register>) -> impl Responder {
|
||||
format!("Hello {} from {}!", params.username, params.country)
|
||||
}` "rust" "" }}
|
||||
</div>
|
||||
<div class="actix-feature" id="routing">
|
||||
@ -132,12 +129,12 @@ fn register(params: web::Form<Register>) -> actix_web::Result<HttpResponse> {
|
||||
URLs and invoke individual handlers. For extra flexibility, scopes
|
||||
can be used.
|
||||
</p>
|
||||
{{ highlight `fn index(_req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok().body("Hello from the index page!")
|
||||
{{ highlight `fn index(_req: HttpRequest) -> impl Responder {
|
||||
"Hello from the index page!"
|
||||
}
|
||||
|
||||
fn hello(path: web::Path<String>) -> HttpResponse {
|
||||
HttpResponse::Ok().body(format!("Hello {}!", &path))
|
||||
fn hello(path: web::Path<String>) -> impl Responder {
|
||||
format!("Hello {}!", &path)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user