You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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: