carllerche / tower-web

A fast, boilerplate free, web framework for Rust
MIT License
980 stars 51 forks source link

Unable to use #[derive(Response)] with #[prost(...)] #203

Open snawaz opened 5 years ago

snawaz commented 5 years ago

The following code fails to compile:

#[derive(Debug, Serialize, Deserialize)] 
#[derive(Extract)]
#[derive(Response)]       // LINE 3
pub struct Example {
    #[prost(string,  tag="1")]  // LINE 5
    pub data: String
}

with this error message:

error[E0658]: The attribute prost is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> src/logic.rs:89:5
|
89 | #[prost(string, tag="1")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

And

That implies Response doesn't work when prost is present.

repnop commented 5 years ago

Just ran into this with diesel's Insertable derive macro as well. The #[table_name = "..."] attribute suddenly becomes unknown and wont compile. To get around this I manually derived Serialize onto the base struct, created a wrapper struct and had to do

#[derive(Response, Serialize)]
#[serde(transparent)]
struct Wrapper(Inner);

(according to the docs, I shouldn't need to derive Serialize there, but got the same error about the serde attribute as above without it)

elpiel commented 5 years ago

Found out the same thing that serde() don't work and you need to manually add Serialize and/or Deserialize to the derives. Should we actually update the docs or there is a bug here?