Skip to content

Missing support for Serde Borrows #920

@HubertMajewski

Description

@HubertMajewski

Is there any fix for using tide's body_json() with serde's borrows in structs?

#[derive(Debug, serde::Deserialize)]
struct MyTest<'a> {
    #[serde(borrow)]
    my_field: &'a str
}

...

tide.at("/test").post(|r: Request<()>| async {
    let body = r.body_json::<MyTest>().await?;

    Ok(Response::new(StatusCode::Ok))
});
Error:
error: implementation of `actions::_::_serde::Deserialize` is not general enough
   --> src/routes/test.rs:109:22
    |
109 |         let body = r.body_json::<MyTest>().await?;
    |                      ^^^^^^^^^ implementation of `actions::_::_serde::Deserialize` is not general enough
    |
    = note: `MyTest<'_>` must implement `actions::_::_serde::Deserialize<'0>`, for any lifetime `'0`...
    = note: ...but `MyTest<'_>` actually implements `actions::_::_serde::Deserialize<'1>`, for some specific lifetime `'1`

Of course I can use String/Vec in the struct directly but I do not want cloning/copying of much larger strings or bytes in my use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions