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

(feat) add mutable indexing, pop #1

Merged
merged 2 commits into from
Dec 20, 2023
Merged

Conversation

dvush
Copy link
Contributor

@dvush dvush commented Dec 18, 2023

No description provided.

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather add more methods to the struct rather than allowing mutable access to the bytes so it's impossible to make an invalid internal representation

@dvush
Copy link
Contributor Author

dvush commented Dec 20, 2023

do you mean having validation or cleanup (setting 4 bits to 0) that makes sure that all bytes in the struct are actually nibbles?

@DaniPopes
Copy link
Member

DaniPopes commented Dec 20, 2023

Yes, but it's impossible if we give out mutable access to the bytes directly (&mut index)

It's currently discouraged to have invalid state but not unsafe nor impossible

@dvush
Copy link
Contributor Author

dvush commented Dec 20, 2023

I think we either:

  1. don't clean nibble input but indicate that methods are for changing nibble content and that would be a caller responsibility (current state)
  2. clean nibble input when inserting (e.g. v & 0x0f) but that should be done for set_at, push and extend_from_slice for consistency.

what do you think?

@DaniPopes
Copy link
Member

1 is ok for now, I think I want to revisit this in the future

@dvush dvush requested a review from DaniPopes December 20, 2023 13:30
@DaniPopes DaniPopes merged commit 33b110b into alloy-rs:master Dec 20, 2023
15 of 16 checks passed
@dvush dvush deleted the pop-idx-mut branch December 20, 2023 13:34
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

Successfully merging this pull request may close these issues.

2 participants