actix / actix/actix-web

Extract path segment struct flattening

Offen
#2,626 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
A-router C-feature
Vorherrschende Sprache
Rust
Sterne
24.8k
Forks
1.9k
Ø Merge
23 Std. 10 Min.
Gemergte PRs (30 T.)
26

Beschreibung

## Expected Behavior

Structs should implement something along the lines of serde's `#[serde(flatten)]` in order to allow nested structs (for usage with extract path segment structs). Example:

```rust
#[route("/{username}/{repository}/tree/{tree}/blob/{blob:.*}", method = "GET")]
pub(crate) async fn view_blob(uri: web::Path) -> Result {}

#[derive(Deserialize)]
pub(crate) struct GitRequest {
pub(crate) username: String,
pub(crate) repository: String
}

#[derive(Deserialize)]
pub(crate) struct BlobRequest {
#[serde(flatten)]
pub(crate) repo: GitRequest,
pub(crate) tree: String,
pub(crate) blob: String
}
```

## Current Behavior

Currently this fails with `unsupported type: any`

## Context

This would help me reduce repeated code such as it is currently [present in GitArena](https://github.com/mellowagain/gitarena/blob/main/src/routes/repository/mod.rs#L23-L34).

[Source Discord thread](https://discord.com/channels/771444961383153695/939266947638493215)

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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