String formatter/builder with easy access of struct fields, which implement the Display trait. If they do not, they can be marked to be ignored.
Usage
Here's most you have to know!
use *; // import everything from prelude
// named struct
// easy derive
// tuple struct
// easy derive
;
// custom pre/postfix per struct + ignore
// easy derive
// custom pre/postfix!
// custom pre/postfix per struct + ignore
// easy derive
// struct with no Display trait
;
About Statics
Prelude imports two static variables [config::STRUNG_PRE] and [config::STRUNG_POST], which can be used to set the prefix and postfix as a configuration. [Strung::strung_static] uses anything called STRUNG_PRE or STRUNG_POST on the file.
[config::static_global] changes these variables, as you saw in the walkthrough, there's another method of changing it per file. It's not included in the walkthrough cause it shadows these variables, it's a macro called [config::static_on_file].
📝 Note: This will maybe change in future, so these variables dont have to always be imported.
But: here's how it can be used for now:
use *; // Import everything from prelude
static_on_file!; // 🌱 Shadow static pre/postfix for this file.
// You know the drill :)
Ignore fields
Sometimes you wanna ignore certain fields - e.g. in these scenarios:
- Get even moar efficiency 📈
- A field-type doesn't implement [std::fmt::Display] This can be done with the #[strung(ignore)] attribute:
use *; // Import everything from prelude
; // 🌱 A struct, not impl Display
] CustomField, // 🌱 Would fail without the attribute!
&'static str
);
❗ Experimental: Cascading ❗
There's also the possibility of cascading. e.g.: $field.0.num, it's experimentally implemented for [Strung::strung_dollar] and [Strung::strung_hashtag] at the moment,
cause it was the easiest to do. 🦀
For this to work, the field-type has to derive [Strung] via derive macro and mark it with the #[strung(cascade)] attribute:
use *;
// #[strung(ignore)] just because none of them are implementing Display!
]C);
]E);