actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.6k stars 1.67k forks source link

can`t add other data #1261

Closed IThawk closed 4 years ago

IThawk commented 4 years ago
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    std::env::set_var("RUST_LOG", "actix_web=info");
    env_logger::init();
    let mgr = Manager::new("redis://127.0.0.1:16379/").unwrap();
    let pool = Pool::new(mgr, 16);
    let pool = Arc::new(pool);
    HttpServer::new(|| {
        App::new()
            // enable logger
            .wrap(middleware::Logger::default())
            .data(web::JsonConfig::default().limit(4096)) // <- limit size of the payload (global configuration)
            .service(web::resource("/extractor").route(web::post().to(index)))
            .service(
                web::resource("/extractor2")
                    .data(web::JsonConfig::default().limit(1024)) // <- limit size of the payload (resource level)
                    .route(web::post().to(extract_item)),
            )
            .service(
                web::resource("/manual")
                    .route(web::post().to(index_manual(web::Payload, pool.clone()))),
            )
            .service(web::resource("/mjsonrust").route(web::post().to(index_mjsonrust)))
            .service(web::resource("/").route(web::post().to(index)))
    })
    .bind("127.0.0.1:8080")?
    .start()
    .await
}

Given error:

error[E0308]: mismatched types
  --> json\src\main.rs:86:81
   |
86 |             .service(web::resource("/manual").route(web::post().to(index_manual(web::Payload,pool.clone()))))
   |                                                                                 ^^^^^^^^^^^^
   |                                                                                 |
   |                                                                                 expected struct `actix_web::types::payload::Payload`, found fn item
   |                                                                                 help: use parentheses to call this function: `web::Payload(...)`
   |
   = note: expected type `actix_web::types::payload::Payload`
              found type `fn(actix_http::payload::Payload) -> actix_web::types::payload::Payload {actix_web::types::payload::Payload}`

error[E0277]: the trait bound `impl core::future::future::Future: actix_web::handler::Factory<_, _, _>` is not satisfied
  --> json\src\main.rs:86:68
   |
86 |             .service(web::resource("/manual").route(web::post().to(index_manual(web::Payload,pool.clone()))))
   |                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `actix_web::handler::Factory<_, _, _>` is not implemented for `impl core::future::future::Future`
JohnTitor commented 4 years ago

Please provide a minimal reproducible example and description, and use code block for readability. Given from error, I suspect you have a typo or simple mistake, could you double-check your code?

IThawk commented 4 years ago

“index_manual” this function. I want to add other function arguments pool

fafhrd91 commented 4 years ago

Code with index_manual is wrong.