-
Notifications
You must be signed in to change notification settings - Fork 68
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
Comments
Instead of modifying the It looks like you are checking |
Hmm... that would probably work. Thank you for the suggestion. That said, I still wonder if it may be useful to allow (un)setting a |
That can be achieved by setting the field to be |
Check out the impl of Flag; you can't unset it and keep the span. https://github.com/TedDriggs/darling/blob/b7a248f8ee4503a949de0730170934587dccfb8e/core/src/util/flag.rs#L45
…________________________________
From: MichiRecRoom ***@***.***>
Sent: Friday, January 17, 2025 8:09:19 PM
To: TedDriggs/darling ***@***.***>
Cc: Ted Driggs ***@***.***>; Comment ***@***.***>
Subject: Re: [TedDriggs/darling] There is no way to set/unset a `Flag` without losing its span information (Issue #315)
Why would you need a method to do that?
Sorry, I neglected to mention that I would want to keep the span info. That's why I'd want a method to do that.
—
Reply to this email directly, view it on GitHub<#315 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABEVHR5KCIZJ76GO4VPNVL32LHHW7AVCNFSM6AAAAABTA3N2HOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOJZGUYTKNRQGY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
@TedDriggs Sorry, let me clarify. While your suggestion to change how
I would much prefer a method on I hope that helps you understand. |
The struct literally cannot be unset while preserving its span; internally it's just |
I'm aware that it's just an But I also don't care how it works internally - I'm a user of If implementing methods to set/unset a If you don't want to do that, then just say so. |
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, becauseSpannedValue<Flag>
does not inheritFlag
'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)
The text was updated successfully, but these errors were encountered: