append_to_string rust macro
The append_to_string!() macro appends every occurance of a literal within a struct or on its own with a .to_string(), converting it to a string. The literals type must implement the .to_string() method.
- converting a literal
// str example
let a = "value".to_string;
let b = append_to_string!;
assert_eq!;
// int example
let a = 42.to_string;
let b = append_to_string!;
assert_eq!;
- converting a Struct
// structs
// simple struct example
let a1 = append_to_string!;
let a2 = A ;
assert_eq!;
// nested struct example
let b1 = append_to_string!;
let b2 = B ;
assert_eq!;
May be useful for when you need to create big structs with String fields but want to keep the code readable or save time by not typing out a conversion method for &str types.
dependencies
this crate uses the syn, quote, and proc_macro2 crates.