On Tue, Sep 16, 2025 at 05:59:18AM -0400, Joel Fernandes wrote:
> Hi Jury,
> Sorry for late reply, I was busy with conference travel. Now I found a 3 hour
> break before my train journey. :-)
> 
> On Wed, Sep 10, 2025 at 09:47:04PM -0400, Yury Norov wrote:
> > On Wed, Sep 10, 2025 at 07:08:43PM -0400, Joel Fernandes wrote:
> > > > You've got only one negative test that covers the .from() method.
> > > > Can you add more?
> > > 
> > > Sure, but note that we can only add negative tests if there is a chance of
> > > failure, which at runtime can mainly happen with the fallible usage (?=>
> > > pattern). Also just to note, we already at ~300 lines of test code now :)
> > > 
> > > > 
> > > > What if I create a bitfield from a runtime value that exceeds
> > > > the capacity?
> > > > 
> > > >     bitfield! {
> > > >         struct bf: u8 {
> > > >             0:0       ready       as bool;
> > > >             1:1       error       as bool;
> > > >             3:2       state       as u32;
> > > Here you mean 'as u8', otherwise it wont compile.
> > 
> > No, I meant u32. Can you explain this limitation in docs please? From
> > a user perspective, the 'state' is a 2-bit variable, so any type wider
> > than that should be OK to hold the data. If it's just an implementation
> > limitation, maybe it's worth to relax it?
> 
> Yes it is a limitation because of the way the code does mask and shifts, it
> requires the width to not exceed the width of the struct itself. Yes, I can
> add a comment.
> 
> I think to do what you want, you have to write it as 'as u8 => u32'.
> Otherwise it wont compile.

I think I am convinced we should fix this, it is too much of a burden to the
user otherwise. 'as u32' should just work out of the box.. I'll add support
for this in v4 but if anyone has any objections, please let me know, thanks!

 - Joel

Reply via email to