Macro tree_decorator::tree_item[][src]

macro_rules! tree_item {
    ($first_style_name:ident $( : $first_style_value:expr )? $( ; $other_style_name:ident $( : $other_style_value:expr )? )* , $str:literal $($arg:tt)*) => { ... };
    ($first_style_name:ident $( : $first_style_value:expr )? $( ; $other_style_name:ident $( : $other_style_value:expr )? )*) => { ... };
    ($str:literal $($arg:tt)*) => { ... };
    () => { ... };
}
Expand description

Prepares tree item with provided styles.

Simplified usage overview:

tree_item!(
    style_a; style_b: custom_value_b; style_c,
    "A literal string which supports {} interpolation {}",
    interpolation_arg_a, interpolation_arg_b
);

Each section, styles, literal string and interpolation args, is optional, but the order should be preserved. An interpolation args couldn’t appears before, or without, a literal string section.

Styles

Every opt-in style must match the name of a defined Style struct field and multiple ones can be declared using ; as it’s separator. A , marks the end of styles section.

Using only it’s name will apply an enable value (see at StyleItemValue).

Note: Order doesn’t matter at styles definition.

Custom Value

Every style item supports a custom value, instead of just using it’s name.

To the block it may not be useful, as it only has two states, on or off (since it’s a bool), but to the entry it’s essential to define which value it should have or it’ll use the default one.

Literal String and Interpolation Args

It’s just a literal string which may contains interpolations (using {}).

Following args should match {} amount.

All the rules and usage are the same as std::format.

Return

It always returns the full representation, including blocks and message, as a &[str](std::str).

Examples

use tree_decorator::{
    decorator::Entry,
    tree_item
};

tree_item!(block, "Items");
tree_item!(entry: Entry::Double; dashed, "Hello {}", "World!");
tree_item!(last, "x = {}, y = {y}", 10, y = 30);