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

Support "while" and "while let" #51

Closed
sanmai-NL opened this issue Oct 16, 2016 · 5 comments
Closed

Support "while" and "while let" #51

sanmai-NL opened this issue Oct 16, 2016 · 5 comments

Comments

@sanmai-NL
Copy link
Contributor

I believe

@while let ...

isn't supported currently (0.12.0). If not, it would be a welcome addition besides @for and @if let.

@lambda-fairy
Copy link
Owner

lambda-fairy commented Oct 16, 2016

I don't think plain @while is supported either.

I'll be happy to accept a PR for this. Should be easy to adapt from the code for @if.

The relevant parts of the code are in maud_macros/src/parse.rs and maud_macros/src/render.rs.

@lambda-fairy lambda-fairy changed the title Support while let Support "while" and "while let" Oct 17, 2016
@lambda-fairy
Copy link
Owner

Don't worry about how I removed the "help wanted" label -- I still want help on this issue!

I just realized that since all issues here can be marked as "help wanted", the label itself is redundant 😄

@sanmai-NL
Copy link
Contributor Author

sanmai-NL commented Oct 17, 2016

Great crate @lfairy, by the way! Keep it up. I appreciate the request for contribution, but I'm a Rust beginner and haven't even had time so far to do much with Rust. I'll have to see whether I can contribute to Maud at all.

I have been reconsidering my request in the meantime. I may not have this down correctly, but I think in all Rust versions up to today (< 1.15) while loops are r-values but must evaluate to (). Some have petitioned for this to be changed, though. Anyway, that means that the obvious @while let statement could not evaluate to e.g. a maud::Markup value. That means that unlike @if and @for, it is useless to have @while let inside html! { ... }. The alternative would be to perform the while let statement before the html! { ... } and then use e.g. @for to pull out the maud::Markup values. What are your thoughts?

@lambda-fairy
Copy link
Owner

@sanmai-NL I can see where you're coming from, but the fact that these Rust control structures return () is a red herring!

Maud doesn't care about what these control structures return. Instead, the body of an @if or @for pushes to an implicit buffer, and it is this buffer that is used as the resulting Markup. In other words: the structure itself always evaluates to () anyway; it's their side effects that we care about. So the RFC isn't relevant to this issue.

You can convince yourself that this is the case by playing around with html_debug!. @while should be expanded in much the same way as @if and @for are now.

@utkarshkukreti
Copy link
Contributor

@sanmai-NL if you want, I'd be happy to submit a PR for this.

utkarshkukreti added a commit to utkarshkukreti/maud that referenced this issue Oct 19, 2016
utkarshkukreti added a commit to utkarshkukreti/maud that referenced this issue Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants