Skip to content
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

Allowing self.field in cmd! macro #62

Open
rewk opened this issue Jan 11, 2023 · 2 comments
Open

Allowing self.field in cmd! macro #62

rewk opened this issue Jan 11, 2023 · 2 comments

Comments

@rewk
Copy link

rewk commented Jan 11, 2023

Hi,

Would it be possible to allow using self.field in cmd! macros ?
For example, this would allow to use a struct to store common args of commands.

struct Commons {
    sh: Shell,
    field: String,
}

impl Commons {
    fn execute(&self) {
        let command = cmd!(self.sh, "echo {self.field}");
        command.run();
    }
}

I have not attempted to make the change, so that i don't know if it would be possible.

If the self. is removed from the above code, the compiler hints at something that would work.

error[E0425]: cannot find value `field` in this scope
  --> src/main.rs:88:13
   |
88 | /             "
89 | |             echo {field}
90 | |             "
   | |_____________^ help: you might have meant to use the available field: `self.field`
@matklad
Copy link
Owner

matklad commented Jan 12, 2023

Good question: this certainly is plausible to implement. I don't remeber why I didn't do it that way, one argument would be that rust format! itself only supports identifiers, but that's a relatively week one.

I think we should just support arbitrary expressions there.

@rewk
Copy link
Author

rewk commented Jan 16, 2023

That would be very nice! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants