actix / actix/actix-web

Compile time type-safe Data extractor

オープン
#1,670 コメント 10 件 リアクション 1 件 担当者 0 名 GitHub で見る
A-web
主要言語
Rust
スター
24.8k
フォーク
1.9k
平均マージ
23時間 10分
マージ済み PR(30日)
26

説明

## 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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。