krdln / command-macros Goto Github PK
View Code? Open in Web Editor NEWRust macros for std::process::Command
License: MIT License
Rust macros for std::process::Command
License: MIT License
The current command!
macro was implemented using rustc's internals, which wasn't pleasant to maintain (also, it was hard to make it work on multiple versions of nightly). Therefore, I decided to drop the support for it.
That macro should be reimplemented using procedural macros 2.0. It's still a nightly feature, but it's a more stable target, and hopefully will stabilize in a near future.
I can't compile the plugin:
error[E0555]: malformed feature attribute, expected #![feature(...)]
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/lib.rs:245:5
|
245 | / feature(
246 | | plugin_registrar,
247 | | rustc_private,
248 | | quote,
249 | | ),
250 | | )]
| |_^
error: cannot find macro `quote_stmt!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:144:37
|
144 | let mut stmts: Vec<Stmt> = vec![quote_stmt!(cx, let mut _cmd = $cmd_expr).unwrap()];
| ^^^^^^^^^^
error: cannot find macro `quote_expr!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:147:45
|
147 | Ok(cx.block_with_expr(span, stmts, Some(quote_expr!(cx, _cmd))))
| ^^^^^^^^^^
error: cannot find macro `quote_expr!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:153:20
|
153 | let cmd_expr = quote_expr!(cx, _cmd);
| ^^^^^^^^^^
error: cannot find macro `quote_expr!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:187:43
|
187 | Condition::Bool(e) => quote_expr!(cx, if $e $then else $els),
| ^^^^^^^^^^
error: cannot find macro `quote_expr!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:188:47
|
188 | Condition::IfLet(p, e) => quote_expr!(cx, if let $p = $e $then else $els)
| ^^^^^^^^^^
error: cannot find macro `quote_expr!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:193:17
|
193 | quote_expr!(cx, for $pat in $expr $body)
| ^^^^^^^^^^
error: cannot find macro `quote_expr!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:202:18
|
202 | let s_expr = quote_expr!(cx, s);
| ^^^^^^^^^^
error: cannot find macro `quote_stmt!` in this scope
--> /home/las/.cargo/registry/src/github.com-1ecc6299db9ec823/command-macros-0.1.10/src/plugin.rs:212:34
|
212 | let mut stmts = vec![quote_stmt!(cx, let mut s = ::std::ffi::OsString::new()).unwrap()];
| ^^^^^^^^^^
error: aborting due to 9 previous errors
If you want more information on this error, try using "rustc --explain E0555"
error: Could not compile `command-macros`.
To learn more, run the command again with --verbose.
The simpler cmd! macro still works thankfully.
This crate already looks like something that is making the invocation of external commands so much easier. Especially after reading how julia handles program invocation, I was wondering whether this crate plans to add features to make pipelines and redirection even easier.
Thank you
This is something I've found myself wanting as I consider migrating a project from using std::process::Command
to using duct::Expression
. Unfortunately there's no easy way to convert between the two types, so the command!
macro can't be used.
I've made an initial implementation & tests using proc_macro; all the functionality of the command!
macro is intact, with the following changes:
{x}
takes a duct::Expression
(x)
takes Into<OsString>
, as required by Expression
, rather than AsRef<OsString>
; as a result, the argument is moved instead of referenced[x]
takes IntoIterator<Item=impl Info<OsStr>>
rather than IntoIterator<Item=impl AsRef<OsStr>>
A slight rough edge is the error message if the user doesn't have the duct crate in dependencies (or it's been renamed) - this gives the error message "could not find duct
in {{root}}
". I'm not sure if it's possible to replace that message.
I'd be happy to update documentation and put up a PR if this would be wanted.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.