I want to get the arguments that are provided to the executable that uses the proc_macro
library. For example, when you run:
cargo run -- -f 69
And you want to get the -f 69
args in proc_macro library, in its sort of runtime, because you need to perform some operations at compile time with them.
When you try to get them using std::env::args()
, you get the following output:
[".../bin/rustc", "--crate-name", "flag", "--edition=2021", "main.rs", "--error-format=json", "--json=diagnostic-rendered-ansi,artifacts,future-incompat", "--crate-type", "bin", "--emit=dep-info,link", "-C", "embed-bitcode=no", "-C", "debuginfo=2", "--check-cfg", "cfg(docsrs)", "--check-cfg", "cfg(feature, values())", "-C", "metadata=0da2a10f35a01285", ... and so on]
There's no -f 69
.
And you can't just call std::env::args()
in your main program and pass that. The context of using the library is attribute macros:
#[flag("-f", "--flag", mandatory, help("test"), type("u64"))]