macro_rules! elements {
() => { ... };
($($element:expr),+ $(,)?) => { ... };
}Expand description
Build a &[DataElement] from a mix of simple values and component lists.
Each entry is an arbitrary expression borrowed through
AsDataElement: a string becomes a simple data element, an array or slice
of strings becomes a composite. This is the shorthand for the mixed-segment
shape that dominates real EDIFACT:
use edifact_rs::{Writer, elements};
// Runtime values, not just literals — the everyday builder shape.
let qualifier = String::from("MS");
let gln = "9900112233445";
let mut w = Writer::new(Vec::new());
w.write_elements("NAD", elements![qualifier.as_str(), [gln, "", "293"]])?;
w.write_elements("DTM", elements![["137", "20260101", "102"]])?;
assert_eq!(
w.finish()?,
b"NAD+MS+9900112233445::293'DTM+137:20260101:102'".to_vec(),
);Composite components must be string slices: a [String; N] cannot borrow
as &[&str] without allocating, so write [id.as_str(), "", agency].
The expansion borrows temporaries, so the result must be consumed within the same statement — passing it directly as an argument, as above, always is.