actix / actix/actix-web

Simplify type for actix_web::App?

Offen
#1,402 4 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
A-web C-improvement
Vorherrschende Sprache
Rust
Sterne
24.8k
Forks
1.9k
Ø Merge
23 Std. 10 Min.
Gemergte PRs (30 T.)
26

Beschreibung

I'm trying to write a function that builds my app, that way it can be reused between my `main` function and my tests. Unfortunate, the type parameters for `actix_web::App` or the `IntoServiceFactory` traits are incredibly verbose. Ideally doing something like this would be straightforward:

```rust
fn create_app() -> actix_web::App {
let templates = tera::Tera::new("templates/*").unwrap();
actix_web::App::new()
.data(AppState { templates })
.route("/", actix_web::web::get().to(index))
.route("/tool/", actix_web::web::post().to(tool))
}
```

I think the right solution might be a type alias that would let you do `-> impl Something`, but I'm open to suggestions on what the right way to handle this ergonomic issue are.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Compare the desired `fn create_app() -> actix_web::App` shape with the current `actix_web::App` and `IntoServiceFactory` APIs, using the issue's shared builder example as the starting point. Done means an agreed ergonomic approach lets the app builder be reused between `main` and tests without requiring verbose type parameters, while preserving the shown routes.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.