synek317 / shellfn

Rust proc macro for easily and safely use shell scripts in rust
MIT License
208 stars 4 forks source link

Using with include_str! #4

Open DerpyCrabs opened 5 years ago

DerpyCrabs commented 5 years ago

I'm trying to include file using include_str! macro: #[shell(cmd = "python -c")] fn run_python(name: &str) -> Result<String, Box<std::error::Error>> { include_str("main.py") } but getting an error on compilation: --> src/main.rs:3:1 | 3 | #[shell(cmd = "python -c")] help: message: Invalid input. Expected fn containing only string literal without any other statements Is it possible to use include_str! macro for this or can I include file through other means?

synek317 commented 5 years ago

Unfortunately, it is currently not possible:

    if let Some(Stmt::Expr(Expr::Lit(ExprLit {
        lit: Lit::Str(ref program),
        ..
    }))) = input.block.stmts.iter().next()

include_str! is a very good extension.