actix / actix/actix-web

Extract path segment struct flattening

Aperta
#2,626 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
A-router C-feature
Lingua principale
Rust
Stelle
24.8k
Fork
1.9k
Merge medio
23h 10m
PR unite (30g)
26

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.