carllerche / tower-web

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

Cannot derive both extract and diesel's traits at the same time #130

Closed steveklabnik closed 5 years ago

steveklabnik commented 5 years ago

I'm not sure if this is a bug in diesel or tower-web, but I think it's in tower-web.

#[derive(Insertable, Extract)]
#[table_name="posts"]
pub struct NewPost<'a> {
    pub title: &'a str,
    pub body: &'a str,
}

This fails with:

error[E0658]: The attribute `table_name` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
  --> src\models.rs:13:3 | 13 | #[table_name="posts"] | ^^^^^^^^^^ | = help: add #![feature(custom_attribute)] to the crate attributes to enable
carllerche commented 5 years ago

So, I failed at git and pushed my fix directly to master and not via a PR :(

Could you check that your case works now against master?

steveklabnik commented 5 years ago

So, with a struct that has lifetimes

error[E0106]: missing lifetime specifier
  --> src\models.rs:52:12
   |
52 | pub struct NewPost<'a> {
   |            ^^^^^^^ expected lifetime parameter

error[E0106]: missing lifetime specifier
  --> src\models.rs:50:22
   |
50 | #[derive(Insertable, Extract)]
   |                      ^^^^^^^ expected lifetime parameter

error[E0106]: missing lifetime specifier
  --> src\main.rs:37:1
   |
37 | / impl_web! {
38 | |     impl Blog {
39 | |         #[get("/")]
40 | |         async fn hello_world(&self) -> String {
...  |
72 | |     }
73 | | }
   | |_^ expected lifetime parameter
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

that said, I think this makes sense, though it could use a better error message.

Changing it to owned types, it works!