-
Preface: I'm new to Rust, so my apologies if my understanding of something or my terminology is wrong. Is there a way that I can define one argument's default value to be based on another argument (ideally with derive method)? I'm working on a tool that will take a single input file, and produces multiple outputs. I have additional optional arguments that allow customizing the output files. If not provided, they instead use the path of the input file, but with a different suffix. As a minimal/contrived example, if the input file is Is there a way I can configure this to be done automatically when parsing the arguments? For example, if I was doing this in a language with inheritance, I could create a subclass of the parser with the additional logic at the subclassed method, but it seems this is not possible in Rust, so is there some way I can specify a post-processing function, or do I just need to write that myself and manually call it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I'd recommend checking out default_value_if. If you are using the derive API, any builder method may be used as a derive attribute. In this case |
Beta Was this translation helpful? Give feedback.
Oh, you aren't wanting a straight "if" condition but a way to transform the user's
arg1
value into a default forarg2
?No, that isn't supported. That seems like something best handled in the application logic.