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

Parse tuple expressions - #608

Merged
djc merged 1 commit into
askama-rs:mainfrom
Kijewski:pr-tuples
Jan 28, 2022
Merged

Parse tuple expressions#608
djc merged 1 commit into
askama-rs:mainfrom
Kijewski:pr-tuples

Conversation

@Kijewski

Copy link
Copy Markdown
Member

Askama understands how to destructure tuples in let and match
statements, but it does not understand how to build a tuple.

This PR fixes this shortcoming.

@Kijewski

Copy link
Copy Markdown
Member Author

I think this would resolve #607 quite nicely. It would compile the example to ↓, which is reasonably similar to what you would write by hand:

match &(
    self.client.can_post(&(self.post)),
    self.client.can_update(&(self.post)),
) {
    (false, false) => {
        writer.write_str("No!")?;
    }
    (can_post, can_update) => {
        writer.write_str("<ul>")?;
        if *(&(can_post) as &bool) {
            writer.write_str("<li>post</li>")?;
        }
        if *(&(can_update) as &bool) {
            writer.write_str("<li>update</li>")?;
        }
        writer.write_str("</ul>")?;
    }
}

Askama understands how to destructure tuples in let and match
statements, but it does not understand how to build a tuple.

This PR fixes this shortcoming.

@djc djc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Kijewski

Copy link
Copy Markdown
Member Author

You're welcome :)

@djc
djc merged commit da0b6ea into askama-rs:main Jan 28, 2022
@Kijewski
Kijewski deleted the pr-tuples branch January 28, 2022 10:23
@djc djc mentioned this pull request Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants