1
0
mirror of https://github.com/actix/actix-website synced 2025-01-22 16:15:56 +01:00

use actix-web 0.7 for examples

This commit is contained in:
Nikolay Kim 2018-07-21 05:21:41 -07:00
parent 324799dd2a
commit 5cd8d2edc8
17 changed files with 28 additions and 28 deletions

View File

@ -1,7 +1,7 @@
[package] [package]
name = "application" name = "application"
version = "0.6.0" version = "0.7.0"
workspace = "../" workspace = "../"
[dependencies] [dependencies]
actix-web = "0.6" actix-web = "0.7"

View File

@ -7,7 +7,7 @@ mod vh;
fn make_app() { fn make_app() {
// <make_app> // <make_app>
fn index(req: HttpRequest) -> impl Responder { fn index(req: &HttpRequest) -> impl Responder {
"Hello world!" "Hello world!"
} }

View File

@ -7,7 +7,7 @@ struct AppState {
counter: Cell<usize>, counter: Cell<usize>,
} }
fn index(req: HttpRequest<AppState>) -> String { fn index(req: &HttpRequest<AppState>) -> String {
let count = req.state().counter.get() + 1; // <- get count let count = req.state().counter.get() + 1; // <- get count
req.state().counter.set(count); // <- store new count in state req.state().counter.set(count); // <- store new count in state

View File

@ -1,7 +1,7 @@
[package] [package]
name = "getting-started" name = "getting-started"
version = "0.6.0" version = "0.7.0"
workspace = "../" workspace = "../"
[dependencies] [dependencies]
actix-web = "0.6" actix-web = "0.7"

View File

@ -2,7 +2,7 @@
extern crate actix_web; extern crate actix_web;
use actix_web::{server, App, HttpRequest}; use actix_web::{server, App, HttpRequest};
fn index(_req: HttpRequest) -> &'static str { fn index(_req: &HttpRequest) -> &'static str {
"Hello world!" "Hello world!"
} }
// </setup> // </setup>

View File

@ -1,10 +1,10 @@
[package] [package]
name = "server" name = "server"
version = "0.6.0" version = "0.7.0"
workspace = "../" workspace = "../"
[dependencies] [dependencies]
actix = "0.5" actix = "0.7"
actix-web = { version="0.6", features=["alpn"] } actix-web = { version="0.7", features=["alpn"] }
futures = "0.1" futures = "0.1"
openssl = "0.10" openssl = "0.10"

View File

@ -2,7 +2,7 @@
use actix_web::{server, App, HttpRequest, Responder}; use actix_web::{server, App, HttpRequest, Responder};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
fn index(req: HttpRequest) -> impl Responder { fn index(req: &HttpRequest) -> impl Responder {
"Welcome!" "Welcome!"
} }

View File

@ -1,11 +1,11 @@
[package] [package]
name = "url-dispatch" name = "url-dispatch"
version = "0.6.0" version = "0.7.0"
workspace = "../" workspace = "../"
[dependencies] [dependencies]
actix = "0.5" actix = "0.7"
actix-web = "0.6" actix-web = "0.7"
futures = "0.1" futures = "0.1"
openssl = "0.10" openssl = "0.10"
serde = "1.0" serde = "1.0"

View File

@ -1,7 +1,7 @@
// <minfo> // <minfo>
use actix_web::{App, HttpRequest, Result}; use actix_web::{App, HttpRequest, Result};
fn index(req: HttpRequest) -> Result<String> { fn index(req: &HttpRequest) -> Result<String> {
let v1: u8 = req.match_info().query("v1")?; let v1: u8 = req.match_info().query("v1")?;
let v2: u8 = req.match_info().query("v2")?; let v2: u8 = req.match_info().query("v2")?;
Ok(format!("Values {} {}", v1, v2)) Ok(format!("Values {} {}", v1, v2))

View File

@ -10,6 +10,6 @@ fn main() {
// </norm> // </norm>
use actix_web::HttpRequest; use actix_web::HttpRequest;
fn index(req: HttpRequest) -> String { fn index(req: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }

View File

@ -11,6 +11,6 @@ fn main() {
use actix_web::HttpRequest; use actix_web::HttpRequest;
fn index(req: HttpRequest) -> String { fn index(req: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }

View File

@ -2,7 +2,7 @@
use actix_web::{http::Method, App, HttpRequest, Result}; use actix_web::{http::Method, App, HttpRequest, Result};
use std::path::PathBuf; use std::path::PathBuf;
fn index(req: HttpRequest) -> Result<String> { fn index(req: &HttpRequest) -> Result<String> {
let path: PathBuf = req.match_info().query("tail")?; let path: PathBuf = req.match_info().query("tail")?;
Ok(format!("Path {:?}", path)) Ok(format!("Path {:?}", path))
} }

View File

@ -1,10 +1,10 @@
// <pred> // <pred>
use actix_web::{http, pred::Predicate, App, HttpMessage, HttpRequest, HttpResponse}; use actix_web::{http, server::Request, pred::Predicate, App, HttpResponse};
struct ContentTypeHeader; struct ContentTypeHeader;
impl<S: 'static> Predicate<S> for ContentTypeHeader { impl<S: 'static> Predicate<S> for ContentTypeHeader {
fn check(&self, req: &mut HttpRequest<S>) -> bool { fn check(&self, req: &Request, state: &S) -> bool {
req.headers().contains_key(http::header::CONTENT_TYPE) req.headers().contains_key(http::header::CONTENT_TYPE)
} }
} }

View File

@ -1,7 +1,7 @@
use actix_web::{App, HttpRequest, HttpResponse}; use actix_web::{App, HttpRequest, HttpResponse};
// <prefix> // <prefix>
fn show_users(req: HttpRequest) -> HttpResponse { fn show_users(req: &HttpRequest) -> HttpResponse {
unimplemented!() unimplemented!()
} }

View File

@ -1,7 +1,7 @@
// <resource> // <resource>
use actix_web::{http::Method, App, HttpRequest, HttpResponse}; use actix_web::{http::Method, App, HttpRequest, HttpResponse};
fn index(req: HttpRequest) -> HttpResponse { fn index(req: &HttpRequest) -> HttpResponse {
unimplemented!() unimplemented!()
} }

View File

@ -1,22 +1,22 @@
#![allow(dead_code)] #![allow(dead_code)]
use actix_web::{http::Method, App, HttpRequest}; use actix_web::{http::Method, App, HttpRequest};
fn get_projects(_: HttpRequest) -> String { fn get_projects(_: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }
fn create_project(_: HttpRequest) -> String { fn create_project(_: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }
fn update_project(_: HttpRequest) -> String { fn update_project(_: HttpRequest) -> String {
unimplemented!() unimplemented!()
} }
fn delete_project(_: HttpRequest) -> String { fn delete_project(_: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }
fn get_tasks(_: HttpRequest) -> String { fn get_tasks(_: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }
fn create_task(_: HttpRequest) -> String { fn create_task(_: &HttpRequest) -> String {
unimplemented!() unimplemented!()
} }
fn update_task(_: HttpRequest) -> String { fn update_task(_: HttpRequest) -> String {

View File

@ -1,7 +1,7 @@
// <ext> // <ext>
use actix_web::{App, Error, HttpRequest, HttpResponse}; use actix_web::{App, Error, HttpRequest, HttpResponse};
fn index(mut req: HttpRequest) -> Result<HttpResponse, Error> { fn index(req: &HttpRequest) -> Result<HttpResponse, Error> {
let url = req.url_for("youtube", &["oHg5SJYRHA0"])?; let url = req.url_for("youtube", &["oHg5SJYRHA0"])?;
assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0"); assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0");
Ok(HttpResponse::Ok().into()) Ok(HttpResponse::Ok().into())