Function derive_more::display::display_as_helper_struct
source · fn display_as_helper_struct() -> TokenStream
Expand description
Create a helper struct that is required by some Display
impls.
The struct is necessary in cases where Display
is derived for an enum
with an outer #[display(fmt = "...")]
attribute and if that outer
format-string contains a single placeholder. In that case, we have to
format twice:
- we need to format each variant according to its own, optional format-string,
- we then need to insert this formatted variant into the outer format-string.
This helper struct solves this as follows:
- formatting the whole object inserts the helper struct into the outer format string,
- upon being formatted, the helper struct calls an inner closure to produce its formatted result,
- the closure in turn uses the inner, optional format-string to produce its
result. If there is no inner format-string, it falls back to plain
$trait::fmt()
.