macro_rules! slack_blocks {
(@acc $v:ident;) => { ... };
(@acc $v:ident; some_into($item:expr) $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; some($item:expr) $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; optionally($pred:expr => $item:expr) $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; optionally_into($pred:expr => $item:expr) $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; ..$iter:expr $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; $kw:ident($pred:expr => $item:expr) $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; $item:expr $(, $($rest:tt)*)?) => { ... };
(@acc $v:ident; $($t:tt)+) => { ... };
() => { ... };
($($t:tt)*) => { ... };
}Expand description
Builds a Vec<T> of block-kit items from a comma-separated list, in one
of two syntaxes that may be freely mixed within a single list:
- Bare form: any expression is pushed via
.into()...itersplices every element ofiterin, each also converted via.into().optionally(pred => item)converts and pushesitemthe same way a bare item does, only whenpredis true, evaluating neitherprednoritemotherwise.Into::intois the identity conversion for an already-typed item, soitemmay be a block struct or an already-built target type; the one thing it cannot be is an expression that itself ends in an untyped.into(), such asmd!(..)/pt!(..)— the same limit a bare item has (seemd!). - Legacy keyword form:
some(item),some_into(item),optionally(pred => item),optionally_into(pred => item), matchingslack_block_item!.
slack_blocks![] and a trailing comma on the last item are both allowed.
See md! for a caveat on placing a bare md!(..)/pt!(..) item
directly in a list.
use slack_morphism::prelude::*;
let show_divider = true;
let items: Vec<SlackBlock> = slack_blocks![
SlackHeaderBlock::new(pt!("Title")),
optionally(show_divider => SlackDividerBlock::new()),
..vec![SlackDividerBlock::new()],
];
assert_eq!(items.len(), 3);
// Legacy keyword form, still supported:
let legacy_items: Vec<SlackBlock> = slack_blocks![
some_into(SlackHeaderBlock::new(pt!("Title"))),
optionally_into(true => SlackDividerBlock::new()),
];
assert_eq!(legacy_items.len(), 2);