fixedbitset
fixedbitset copied to clipboard
Implement IndexMut
Allows syntax like received[id] = true;
I don't think it's possible to implement this as the Index
implementation uses borrows on constants &true
and &false
. Providing a &mut bool
return value is likely impossible.
Pretty sure you just need a wrapper type. Don't return bool, return some wrapper type that implements DerefMut
for bool. That way you can call set in the deref implementation.
IndexMut
relies on Index
's associated type. We'd need to do the same for Index
and I'm not sure if that's desirable from an API design perspective.
Ah shoot, forgot about that. I think it should mostly work? Off the top of my head, if a user stores the result of bitset[blah]
in something that uses type inference, things might get weird. They'll probably store the wrapper type instead of the bool. Then again, they would have been storing &bool
s before, so maybe that's already broken and it doesn't matter?