bpaf_derive: allow arbitrary expression in external#450
Conversation
|
Yeah, this looks similar to what I'd write myself. I ended up not implementing it since I don't really like to encourage writing more code in the non-rust portion of the language, but maybe it's not that bad... To get this merged we'll need to update the documentation as well. Can you explain your use case a bit more? |
My use case is that I wanted a boolean parser with E.g. As an aside... it'd be even better to have a shorthand boolean-only version of E.g. Then my use case could just be ! 😄 |
So here I was thinking about the alternative attribute, struct Options {
#[bpaf(external_with(make_explicit_not))]
/// to foo or not to foo
foo: bool
}
fn make_explicit_not(name: &'static str, help: Option<'static str>) -> impl Parser<bool> {
// do whatever
}Would it work better in your case? |
That could work! My only hesitation is the limitation on signature of the external function. (Why would |
|
Say I'm trying to reimplement a parser similar to fn dd_style(name: &'static str, metavar: &'static str, help: &'static str) -> impl Parser<String> {
...
}For derive implementation - I'd want to have help messages as well and this should be different help for each argument. If help lives inside of the callee - I'll need a function per agument. Not ideal. On the other hand I already have help as a doc comment on the Now that I'm thinking of it - it should probably accept additional parameters, similar to what you did to pass the metavar, if needed. Does this makes sense to you? From your example - this won't work in the current version. pub fn boolean_toggle(name_long: &str) -> impl Parser<Option<bool>> {
toggle_flag(long(name_long), true, long(format!("no-{name_long}")), false)
}Would you be interested in adding support for this extended variant as well, plus some docs? Should be close to what you have already, just inserts implicit name and help or index and help (for tuple structs) parameters in addition to what's present. |
Resolves #270
Does this seem like the right approach? I'm learning Rust, found myself also wanting the feature from #270, so decided to see if I could implement it myself. 🙂
Let me know what you think!