-
Make sure you completed the following tasks
Describe your use caseIf I have a number of commands that operate similarly, I may structure the command as such: /// Base action which provides the necessary parameters
#[derive(Clap, Debug, Clone, PartialEq)]
struct BaseAction {
filename: String,
// It's fair to assume this is a more complex struct, given its use case
}
/// Does some action
type Action1 = BaseAction;
/// Does some other action
type Action2 = BaseAction;
/// Do an action
#[derive(Clap, Debug, Clone, PartialEq)]
enum Do {
One(Action1),
Two(Action2),
} However when this is done, the help generated uses the comment Describe the solution you'd likeIdeally using the same code as before, clap's derivation would see that the type of Alternatives, if applicableThe current alternative is somewhat bad IMO, but does work. That is to comment on the variant itself. This is less than ideal because there is no documentation on the type, or duplication in documentation, which is too easy to get out of sync as it is. /// Base action which provides the necessary parameters
#[derive(Clap, Debug, Clone, PartialEq)]
struct BaseAction {
filename: String,
// It's fair to assume this is a more complex struct, given its use case
}
type Action1 = BaseAction;
type Action2 = BaseAction;
/// Do an action
#[derive(Clap, Debug, Clone, PartialEq)]
enum Do {
/// Does some action
One(Action1),
/// Does some other action
Two(Action2),
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's not how rust derive macros work. They can't see outside the scope they are defined for. And The alternative is the recommended way to do this. Infact you don't even need to define the types separately here. /// Do an action
#[derive(Clap, Debug, Clone, PartialEq)]
enum Do {
/// Does some action
One(BaseAction),
/// Does some other action
Two(BaseAction),
} |
Beta Was this translation helpful? Give feedback.
That's not how rust derive macros work. They can't see outside the scope they are defined for. And
type
statements don't support derive macros either. Basically, this is impossible as of now.The alternative is the recommended way to do this. Infact you don't even need to define the types separately here.