Replies: 1 comment
-
First, this is less clumsy for the caller:
(Also see how this duplicates Second, I basically have the same problem, thought about this a bit and I think the nicest semantics would be to use a normal rust enum:
with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Thank you for the wonderful library.
I don't know how to name what I'm looking for, so I'm calling them polymorphic bitfields by analogy with a similar concept I've seen in SQL. The idea is that the bitfield has two parts: a type field, and a payload that we interpret differently depending on the type.
As a contrived but simple example, consider a
u16
where the first bit is0
if the remainder should be interpreted as au15
and a1
if the remainder should be interpreted as fiveu3
s.Currently, I manage this behavior as follows:
But this feels clumsy to me, as it seems that the caller can
unwrap_as_type_one
even if the payload actually corresponds toTypeTwo
.I read through the documentation for
modular_bitfield
, and while I learned a lot of wonderful things about this library, I'm not sure how to best implement what I describe above. I would be grateful for any help you could provide.Beta Was this translation helpful? Give feedback.
All reactions