1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

do not use with2

This commit is contained in:
Nikolay Kim 2018-06-01 11:31:53 -07:00
parent 32287e37bc
commit 96a77890ba
6 changed files with 36 additions and 15 deletions

View File

@ -14,12 +14,6 @@ matrix:
allow_failures: allow_failures:
- rust: nightly - rust: nightly
#rust:
# - 1.21.0
# - stable
# - beta
# - nightly-2018-01-03
env: env:
global: global:
# - RUSTFLAGS="-C link-dead-code" # - RUSTFLAGS="-C link-dead-code"
@ -40,7 +34,11 @@ before_script:
script: script:
- | - |
cd async_db && cargo check && cd ..
cd async_ex1 && cargo check && cd ..
cd basics && cargo check && cd .. cd basics && cargo check && cd ..
cd cookie-auth && cargo check && cd ..
cd cookie-session && cargo check && cd ..
cd diesel && cargo check && cd .. cd diesel && cargo check && cd ..
cd hello-world && cargo check && cd .. cd hello-world && cargo check && cd ..
cd http-proxy && cargo check && cd .. cd http-proxy && cargo check && cd ..
@ -51,9 +49,12 @@ script:
cd r2d2 && cargo check && cd .. cd r2d2 && cargo check && cd ..
cd redis-session && cargo check && cd .. cd redis-session && cargo check && cd ..
cd state && cargo check && cd .. cd state && cargo check && cd ..
cd static_index && cargo check && cd ..
cd template_askama && cargo check && cd ..
cd template_tera && cargo check && cd .. cd template_tera && cargo check && cd ..
cd tls && cargo check && cd .. cd tls && cargo check && cd ..
cd unix-socket && cargo check && cd .. cd unix-socket && cargo check && cd ..
cd web-cors/backend && cargo check && cd ../.. cd web-cors/backend && cargo check && cd ../..
cd websocket && cargo check && cd .. cd websocket && cargo check && cd ..
cd websocket-chat && cargo check && cd .. cd websocket-chat && cargo check && cd ..
cd websocket-tcp-chat && cargo check && cd ..

18
Cargo.lock generated
View File

@ -164,6 +164,24 @@ dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "async_db"
version = "0.1.0"
dependencies = [
"actix 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2_sqlite 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.10" version = "0.2.10"

View File

@ -24,8 +24,8 @@ use actix_web::{
}; };
use diesel::prelude::*; use diesel::prelude::*;
use diesel::r2d2::{ConnectionManager, Pool}; use diesel::r2d2::ConnectionManager;
use futures::future::Future; use futures::Future;
mod db; mod db;
mod models; mod models;
@ -39,7 +39,9 @@ struct AppState {
} }
/// Async request handler /// Async request handler
fn index(name: Path<String>, state: State<AppState>) -> FutureResponse<HttpResponse> { fn index(
(name, state): (Path<String>, State<AppState>),
) -> FutureResponse<HttpResponse> {
// send async `CreateUser` message to a `DbExecutor` // send async `CreateUser` message to a `DbExecutor`
state state
.db .db
@ -72,7 +74,7 @@ fn main() {
App::with_state(AppState{db: addr.clone()}) App::with_state(AppState{db: addr.clone()})
// enable logger // enable logger
.middleware(middleware::Logger::default()) .middleware(middleware::Logger::default())
.resource("/{name}", |r| r.method(http::Method::GET).with2(index)) .resource("/{name}", |r| r.method(http::Method::GET).with(index))
}).bind("127.0.0.1:8080") }).bind("127.0.0.1:8080")
.unwrap() .unwrap()
.start(); .start();

View File

@ -69,7 +69,7 @@ fn graphiql(_req: HttpRequest<AppState>) -> Result<HttpResponse, Error> {
} }
fn graphql( fn graphql(
st: State<AppState>, data: Json<GraphQLData>, (st, data): (State<AppState>, Json<GraphQLData>),
) -> FutureResponse<HttpResponse> { ) -> FutureResponse<HttpResponse> {
st.executor st.executor
.send(data.0) .send(data.0)
@ -96,7 +96,7 @@ fn main() {
App::with_state(AppState{executor: addr.clone()}) App::with_state(AppState{executor: addr.clone()})
// enable logger // enable logger
.middleware(middleware::Logger::default()) .middleware(middleware::Logger::default())
.resource("/graphql", |r| r.method(http::Method::POST).with2(graphql)) .resource("/graphql", |r| r.method(http::Method::POST).with(graphql))
.resource("/graphiql", |r| r.method(http::Method::GET).h(graphiql)) .resource("/graphiql", |r| r.method(http::Method::GET).h(graphiql))
}).bind("127.0.0.1:8080") }).bind("127.0.0.1:8080")
.unwrap() .unwrap()

View File

@ -1,5 +1,5 @@
max_width = 89 max_width = 89
reorder_imports = true reorder_imports = true
wrap_comments = true #wrap_comments = true
fn_args_density = "Compressed" fn_args_density = "Compressed"
#use_small_heuristics = false #use_small_heuristics = false

View File

@ -15,7 +15,7 @@ struct AppState {
} }
fn index( fn index(
state: State<AppState>, query: Query<HashMap<String, String>>, (state, query): (State<AppState>, Query<HashMap<String, String>>),
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
let s = if let Some(name) = query.get("name") { let s = if let Some(name) = query.get("name") {
// <- submitted form // <- submitted form
@ -47,7 +47,7 @@ fn main() {
App::with_state(AppState{template: tera}) App::with_state(AppState{template: tera})
// enable logger // enable logger
.middleware(middleware::Logger::default()) .middleware(middleware::Logger::default())
.resource("/", |r| r.method(http::Method::GET).with2(index)) .resource("/", |r| r.method(http::Method::GET).with(index))
}).bind("127.0.0.1:8080") }).bind("127.0.0.1:8080")
.unwrap() .unwrap()
.start(); .start();