#[derive(NetworkFormatter)]
{
// Attributes available to this derive:
#[formatter]
}
Expand description
Automatically implement the NetworkFormatter for the given type. The strings are generated
similar to the derived std::fmt::Debug implementation.
You can control the way in which individual fields are formatted. To do so, you can use the
#[formatter(...)] attribute. You can use the following values:
skipwill skip that field entirely.fmt = ...controls which function to use for the (single-line) formatting. You have the following options:path::to::fn: A path to a function that takes a reference to the value and to the network the same function signature asNetworkFormatter::fmt. If you pick a custom function without specifying amultilineattribute, then the same function will be used when formatting the field for multiple lines."fmt": The default (single-line) formatter (used by default). SeeNetworkFormatter::fmt."fmt_set: Format any iterable as a set. SeeNetworkFormatterSequence::fmt_set."fmt_list: Format any iterable as a list. SeeNetworkFormatterSequence::fmt_list."fmt_path: Format any iterable as a path, in the form ofa -> b -> c. SeeNetworkFormatterSequence::fmt_path."fmt_map: Format the content as a mapping. SeeNetworkFormatterMap::fmt_map."fmt_map: Format the content as a mapping. SeeNetworkFormatterMap::fmt_map."fmt_path_options: Format a nested iterator as a path option set, in the form ofa -> b | a -> b -> c. SeeNetworkFormatterNestedSequence::fmt_path_options."fmt_path_set: Format a nested iterator as a path option set, in the form of{a -> b, a -> b -> c}. SeeNetworkFormatterNestedSequence::fmt_path_set."fmt_ext: Format any iterable using the extension formatter, seeNetworkFormatterExt::fmt_ext.
multiline = ...controls which function to use for the multiline formatting. By default, it will pick the multi-line variant of thefmtoption (for instance, settingfmt = "fmt_set"will automatically configuremultiline = "fmt_set_multiline"). In addition to those, you have the following options:path::to::fn: A path to a function that takes a reference to the value, to the network, and an usize counting the current indentation level. It must have the same function signature asNetworkFormatter::fmt_multiline_indent."fmt_multiline": The default multi-line formatter (used by default). SeeNetworkFormatter::fmt_multiline_indent."fmt_set_multiline: Format any iterable as a set. SeeNetworkFormatterSequence::fmt_set_multiline."fmt_list_multiline: Format any iterable as a list. SeeNetworkFormatterSequence::fmt_list_multiline."fmt_map_multiline: Format the content as a mapping. SeeNetworkFormatterMap::fmt_map_multiline."fmt_path_multiline: Format the content as a set of paths. SeeNetworkFormatterNestedSequence::fmt_path_multiline.
use bgpsim::prelude::*;
#[derive(NetworkFormatter)]
struct Foo {
/// Will be printed regularly
counter: usize,
// Will be hidden
#[formatter(skip)]
internal_counter: usize,
/// This will print a path instead of a list
#[formatter(fmt = "fmt_path")]
path: Vec<RouterId>,
/// Do not print this field with multiple lines
#[formatter(multiline = "fmt")]
visited: HashSet<RouterId>,
}