fixedbitset icon indicating copy to clipboard operation
fixedbitset copied to clipboard

Implement IndexMut

Open SUPERCILEX opened this issue 2 years ago • 4 comments

Allows syntax like received[id] = true;

SUPERCILEX avatar Apr 03 '22 22:04 SUPERCILEX

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.

james7132 avatar Jan 16 '23 01:01 james7132

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.

SUPERCILEX avatar Jan 16 '23 01:01 SUPERCILEX

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.

james7132 avatar Jan 16 '23 02:01 james7132

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 &bools before, so maybe that's already broken and it doesn't matter?

SUPERCILEX avatar Jan 16 '23 02:01 SUPERCILEX