macro_rules! arr {
() => { ... };
($($item:expr),+ $(,)?) => { ... };
}
Expand description
Creates a fixed-size array literal with each element converted with Into
.
You’ll probably need a hint for the target type of items in the array if the compiler can’t infer it from its usage.
This is similar in spirit to the bon::vec!
macro, but it’s for arrays.
See bon::vec!
docs for details.
Same example as in bon::vec!
, but using this macro. It works with array
as well because Command::args
accepts any value that implements IntoIterator
:
fn convert_media(input_extension: &str, output_extension: &str) -> std::io::Result<()> {
let ffmpeg_args: [String; 4] = bon::arr![
"-i",
format!("input.{input_extension}"),
"-y",
format!("output.{output_extension}"),
];
std::process::Command::new("ffmpeg").args(ffmpeg_args).output()?;
Ok(())
}
This macro doesn’t support [expr; N]
syntax, since it’s simpler to
just write [expr.into(); N]
instead.