Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IndexMut #76

Open
SUPERCILEX opened this issue Apr 3, 2022 · 4 comments
Open

Implement IndexMut #76

SUPERCILEX opened this issue Apr 3, 2022 · 4 comments

Comments

@SUPERCILEX
Copy link

Allows syntax like received[id] = true;

@james7132
Copy link
Collaborator

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.

@SUPERCILEX
Copy link
Author

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.

@james7132
Copy link
Collaborator

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 james7132 reopened this Jan 16, 2023
@SUPERCILEX
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants