actix / actix/actix-web

Extract path segment struct flattening

Open
#2,626 1 comment 0 reactions 0 assignees View on GitHub
A-router C-feature
Dominant language
Rust
Stars
24.8k
Forks
1.9k
Avg merge
23h 10m
Merged PRs (30d)
26

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.