Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

empty struct fails with proc macro #101

Closed
drahnr opened this issue Jul 4, 2018 · 8 comments
Closed

empty struct fails with proc macro #101

drahnr opened this issue Jul 4, 2018 · 8 comments

Comments

@drahnr
Copy link
Contributor

drahnr commented Jul 4, 2018

Hi djc,

not sure if this is a general rust issue or an implementation detail in askama (I might be just too silly to pass the right terms to my fav search engine).

#[derive(Template)];
struct Index; // no struct members
error: proc-macro derive panicked
  --> src/main.rs:18:10
   |
18 | #[derive(Template)]
   |          ^^^^^^^^
   |
   = help: message: derive(Template) only works for struct items

error: aborting due to previous error

error: Could not compile `cantaloupe`.

To learn more, run the command again with --verbose.

$ rustc --version
rustc 1.27.0 (3eda71b00 2018-06-19)
@djc
Copy link
Collaborator

djc commented Jul 4, 2018

This is Askama-specific. It probably works if you make it struct Index {};?

@drahnr
Copy link
Contributor Author

drahnr commented Jul 4, 2018

Yes indeed! Adding {} makes it compile (if I also add either a new or default impl since Index.render().unwrap() won't work anymore).

@djc
Copy link
Collaborator

djc commented Jul 4, 2018

You can similarly do Index {}.render().unwrap() (maybe needs some extra parentheses).

@drahnr
Copy link
Contributor Author

drahnr commented Jul 4, 2018

True, didn't think of that.

EDIT:

Just verified: Works as expected.

@djc djc closed this as completed in 191e56a Jul 4, 2018
djc added a commit that referenced this issue Jul 4, 2018
@djc
Copy link
Collaborator

djc commented Jul 4, 2018

So I've decided to lift the restrictions here, so you can now use any kind of struct as the context.

@djc
Copy link
Collaborator

djc commented Jul 4, 2018

And thanks for reporting!

@drahnr
Copy link
Contributor Author

drahnr commented Jul 4, 2018

Awesome, thank you! As always, incredible turn around times :)

@djc
Copy link
Collaborator

djc commented Jul 4, 2018

It helps that we're timezone-aligned 😊

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants