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

Comments

Projects
None yet
3 participants
@sanmai-NL
Copy link
Contributor

sanmai-NL commented Oct 16, 2016

I believe

@while let ...

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

@lfairy

This comment has been minimized.

Copy link
Owner

lfairy 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.

@lfairy lfairy added the help wanted label Oct 17, 2016

@lfairy lfairy changed the title Support while let Support "while" and "while let" Oct 17, 2016

@lfairy lfairy added easy enhancement and removed help wanted labels Oct 17, 2016

@lfairy

This comment has been minimized.

Copy link
Owner

lfairy commented Oct 17, 2016

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

This comment has been minimized.

Copy link
Contributor

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?

@lfairy

This comment has been minimized.

Copy link
Owner

lfairy commented Oct 17, 2016

@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

This comment has been minimized.

Copy link
Contributor

utkarshkukreti commented Oct 17, 2016

@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

@lfairy lfairy closed this in #55 Oct 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment