Hello there!
I've got a quick question, does anyone know about a macro, that automatically derives macros for field setters?
I've got an example, of the code I'd like to have generated
struct Config {
from: String,
to: String,
output: String,
}
impl Config {
fn new() -> Config {
Config {
from: String::new(),
to: String::new(),
output: String::new(),
}
}
fn to(mut self, value: String) -> Config {
self.to = value;
self
}
fn output(mut self, value: String) -> Config {
self.output = value;
self
}
fn from(mut self, value: String) -> Config {
self.from = value;
self
}
}
As you see, the to()
, output()
and from()
methods look quite generic and the process of writing them could be automated. Does anyone know about a macro in a crate that does just that?
Thank you!