Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 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
Owner

@djc djc commented Jul 4, 2018

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

@drahnr
Copy link
Contributor Author

@drahnr 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
Owner

@djc djc commented Jul 4, 2018

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

@drahnr
Copy link
Contributor Author

@drahnr drahnr commented Jul 4, 2018

True, didn't think of that.

EDIT:

Just verified: Works as expected.

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

@djc 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
Owner

@djc djc commented Jul 4, 2018

And thanks for reporting!

@drahnr
Copy link
Contributor Author

@drahnr drahnr commented Jul 4, 2018

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

@djc
Copy link
Owner

@djc djc commented Jul 4, 2018

It helps that we're timezone-aligned 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.