I don't want to use prometheus crate(https://crates.io/crates/prometheus) to generate metrics, rather I want custom serde to this job.
I have a structure which contains counters
# HELP authentication_requests Stats Authentication Requests
# TYPE authentication_requests counter
authentication_requests 2
# HELP <variable_name> <custom string>
# TYPE <variable_name> <custom_string>
<variable_name> value
ie serde should pick up variable name by itself, create prometheus metrics as above and return. And struct has 100's of variables, serde should do same for all variables and return concatenated string. Is it possible anyhow?
I still don't see how serde would help for this use case. It's a serialization library, but you seem to want to format some values rather than serializing them. Also, it doesn't support those <custom_string>.
I think you're better off writing a declarative macro with macro_rules that takes care to generate the struct and the code for printing it.
If you do want to stick with Serde, you should read through their documentation on implementing a custom data format. However, at the end of the day, you'll still have to use string formatting to actually implement it.