utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntax Question

AblatedSprocket opened this issue · comments

I really like this crate and I want to use it in my projects, but I'm getting a syntax error I'm having trouble debugging. I see that this repo hasn't seen much activity lately but I'm hoping this gets seen.

My template:

const BASE_DIR: &str = "/foo/bar";
Markup::define! {
    Home {
        {markup::doctype()}
        html [lang="en"] {
            body {
                @match {fs::read_dir(BASE_DIR)} {
                    Ok(dirs) => {
                        @for dir in dirs {
                            @match {dir.ok()} {
                                Some(item) => if item.path().is_dir() {
                                    {item.file_name()}
                                }
                                None => {}
                            }
                        }
                    }
                    Err(error) => {}
                }
            }
        }
    }
}

The compiler says it's expecting an identifier at @match {dir.is_ok()} {. I googled around but couldn't find anything about this. Any help would be appreciated.

Could you try changing @for dir in dirs to @for dir in {dirs} in the previous line?

Btw, syn now includes a function to fix this {} hack this crate requires: dtolnay/syn#848. I'll see if I can work on using it soon.

I tried that, but it didn't work. After playing with dereferencing different things like you do in the documentation, I eventually was able to resolve it by calling .into_iter() on dirs in the for statement. I was expecting a different compiler message for this type of error.

EDIT: I'm really enjoying this crate, thanks for putting the time into this. It's a little hard to debug, but it's so worth it for everything it lets you do.

This was fixed in this commit: 77c56b2 on Aug 7, forgot to refer to this issue. Let me know if something still doesn't work!