Skip to content

@let and @for should support type annotations #73

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

Closed
lambda-fairy opened this issue Feb 1, 2017 · 2 comments
Closed

@let and @for should support type annotations #73

lambda-fairy opened this issue Feb 1, 2017 · 2 comments

Comments

@lambda-fairy
Copy link
Owner

lambda-fairy commented Feb 1, 2017

The following syntax should work, but doesn't:

html! {
    @let foo: Bar = baz() {
        // ...
    }
}

See #72.

@trombonehero
Copy link

The same is probably true of @for as well, e.g.:

@for u: User in self.0.as_ref() {
    tr {
        td (u.name)
        td (u.email)
        /* ... */
    }
}

@lambda-fairy lambda-fairy changed the title @let syntax should support type annotations @let and @for syntax should support type annotations Mar 4, 2017
@lambda-fairy lambda-fairy changed the title @let and @for syntax should support type annotations @let and @for should support type annotations Mar 4, 2017
@lambda-fairy
Copy link
Owner Author

The following code works on master:

#[test]
fn let_type_ascription() {
    let s = html! {
        @let mut x: Box<Iterator<Item=u32>> = Box::new(vec![42].into_iter()) {
            "I have " (x) " cupcakes!"
        }
    }.into_string();
    assert_eq!(s, "I have 42 cupcakes!");
}

I have added this as a test in 4a73399.

Type ascription in for patterns isn't supported in Rust proper, so I'll consider that a wontfix. See rust-lang/rfcs#354.

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

2 participants