actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Extract path segment struct flattening

Open mellowagain opened this issue 3 years ago • 1 comments

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:

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

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

Source Discord thread

mellowagain avatar Feb 04 '22 21:02 mellowagain

Is this still planned/any workarounds? This feature would be awesome to reduce loads of duplicate code.

namebee avatar Nov 04 '23 01:11 namebee