Skip to content
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

There is no way to set/unset a Flag without losing its span information #315

Open
LikeLakers2 opened this issue Dec 4, 2024 · 0 comments

Comments

@LikeLakers2
Copy link

LikeLakers2 commented Dec 4, 2024

Hi! I was doing some derive-macro practice over at https://github.com/LikeLakers2/michis_rand_distr_derive.

In the midst of this, I found myself wanting to set a Flag value - but found there was no way to do so without losing its span information.

In my specific case, I have two options that can be applied to enum variants - a weight (how likely that variant is to be selected) and a skip option (if specified, the variant will never be selected). What I wanted to do was, if the weight was a zero-like value, erase the weight value and enable the skip flag. Unfortunately, I found there was no way to do this with Flag alone.

I did find a solution, SpannedValue<Flag>, which allows me to recreate the Flag value without (technically) losing the span information. However, this feels hacky, as now I'm storing the Span twice - and more importantly, I am forced to add #[darling(default)] to that field, because SpannedValue<Flag> does not inherit Flag's property of being inherently optional.

I'm hoping something can be done to handle this.

(P.S. If you're curious about the relevant code: https://github.com/LikeLakers2/michis_rand_distr_derive/blob/98200c0ed81ddace432787e4fe4214db6085049e/src/standard_distribution/derive_variant.rs#L19-L27)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant