rust_script_ext::prelude

Macro cargs

Source
cargs!() { /* proc-macro */ }
Expand description

Construct a [String] array from a list of arguments.

This macro is primarily for use with cmd!, but can also be independently used, a great location is Command::args.

Arguments are delimited by commas, any text between delimiters is stringified and passed through. Arguments wrapped in braces ({ ... }) are treated as expressions to be evaluated. This effectively writes { ... }.to_string().

arg1, arg2/foo, {expr}

ยงExample


let x = "hello";
let c = cargs!(foo, bar/zog, {x}, {1 + 2});
assert_eq!(c, [
    "foo".to_string(),
    "bar/zog".to_string(),
    "hello".to_string(),
    "3".to_string()
]);