Compile time type-safe Data extractor
- Langage dominant
- Rust
- Étoiles
- 24.8k
- Forks
- 1.9k
- Merge moyen
- 23 h 10 min
- PR mergées (30 j)
- 26
Description
## Expected Behavior
It should error on compile time, or at least error when starting the application but not when user sends the request (this is probably harder).
## Current Behavior
It errors on run time, and it is hard to figure out why does it fail if a more complex type is involved, users might get frustrated since it compiles but it errors when the user sends the request. Rocket have this issue too, tide does not have it now but might soon have it.
## Possible Solution
- add a single state to `AppState` in addition to current hashmap data which may improve performance and provides compile time guarantee
- use a different type for the state, maybe `State` rather than `Data` to only allow an instance of type-safe data?
- better error message and suggestion, suggest how to fix by using the correct data and type, this is probably the hardest method
## Steps to Reproduce (for bugs)
```rust
use actix_web::*;
#[get("/")]
async fn index(_data: web::Data) -> impl Responder {
"Hello world"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index))
.bind("[::]:8080")?
.run()
.await
}
```
```
$ curl 127.1:8080
App data is not configured, to configure use App::data()
```
Even if I did `App::new().data("aoeu")`, it still shows `App data is not configured, to configure use App::data()` which is not true at all.
## Context
This simple example is easy to figure out what went wrong, since we have no data assigned for the application. Last time (during an interview T_T) I was dealing with some types that involves `Arc` and is more complicated and I took some time to figure out why was the application failing when it compiled successfully and is not as straightforward, IIRC I was changing from `data` to `app_data`.
## Your Environment
* Rust Version (I.e, output of `rustc -V`): rustc 1.46.0 (04488afe3 2020-08-24)
* Actix Web Version: 3.0.0
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.