-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can ArgEnum
be both more general and performant?
#2799
Comments
not |
One possible soluion would be returning an array using const generics and using the 2021 edition At least in theorie. |
ArgValue
be both more general and performant?ArgEnum
be both more general and performant?
@pksunkara posted the following snippet as one idea trait ArgEnum<const COUNT: usize>: Sized {
fn variants() -> [Self; COUNT];
}
enum E {
One,
Two,
}
impl ArgEnum<2> for E {
fn variants() -> [Self; 2] {
[Self::One, Self::Two]
}
}
fn main() {} |
@ModProg are you referring to using I see this is a trade off of making the trait harder to use vs requiring Personally, I feel the I recommend we close this, creating a new issue based on specific user feedback if it comes in. |
yes.
The only thing about this that makes me consider it is, that most people will only derive but never implement it, so this only affects a small number of people. And while the But I also see another implementation that just moves the |
I agree with @ModProg regarding the estimates of how many use what kind of implementation.
Do we have a clear example on how to achieve this? |
This was the way it was done before, it was changed here: |
To clarify, I'm not concerned about the implementer. With that said, I have a PR out for one hand-written However, creating a trait that can only be used in very specific ways because of the way the generic parameter is defined, severely limits our ability to evolve clap. |
@ModProg, I thought the inherent |
It is, but it more enables the inherent The problem with the "generated" form is that we have to create the ArgValue for each call. tho I don't know if there is some optimazation happening because it technicly is a constant value even tho due to alias being a Vec we cannot declare it as const. Another though is, we could also create the actual ArgValue during deriving, call |
The advantage to using the |
I've only skimmed this issue, but in general I don't believe adding a const generic type argument to The cost however is a generic argument that's not entirely clear at first glance what it's for: I would like to see improvement around ArgEnum for sure, but I think this is one of those issues that we can place on the back burner and garner some good ideas as v3 fleshes. |
For comparison purposes Originalpub trait ArgEnum: Sized {
const VARIANTS: &'static [&'static str];
fn from_str(input: &str, case_insensitive: bool) -> Result<Self, String>;
fn as_arg(&self) -> Option<&'static str>;
}
Current Solutionpub trait ArgEnum: Sized + Clone {
fn value_variants<'a>() -> &'a [Self];
fn from_str(input: &str, case_insensitive: bool) -> Result<Self, String>;
fn to_arg_value<'a>(&self) -> Option<ArgValue<'a>>;
}
|
I am happy with where it is for 3.0, but we can keep this open for future. Removing the milestone. |
I feel like our current option is "good enough" until we get real world use cases with problems. Closing for now |
#2762 initially had common API calls for
ArgValue
allocating aVec
. We instead dropped that at the cost of adding theClone
super trait.Can we do better?
The text was updated successfully, but these errors were encountered: