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

Add ZeroVec::iter_mut() #1128

Merged
merged 7 commits into from
Sep 30, 2021
Merged

Conversation

Manishearth
Copy link
Member

No description provided.

@Manishearth
Copy link
Member Author

I elected to not make make_mut() public since I'd like to do all of that holistically in #676

zbraniecki
zbraniecki previously approved these changes Sep 30, 2021
utils/zerovec/src/zerovec/mod.rs Outdated Show resolved Hide resolved
utils/zerovec/src/zerovec/mod.rs Outdated Show resolved Hide resolved
Comment on lines 441 to 443
let mut aligned = T::from_unaligned(item);
f(&mut aligned);
*item = aligned.as_unaligned()
Copy link
Member

@sffc sffc Sep 30, 2021

Choose a reason for hiding this comment

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

Optional: maybe

*item = f(T::from_unaligned(item)).as_unaligned();

where the function returns a value rather than mutating the input?

Copy link
Member Author

Choose a reason for hiding this comment

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

IME it's more ergonomic to work with mutables in closure rather than having to figure out how to return things

Copy link
Member Author

Choose a reason for hiding this comment

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

Also I'm matching Iterator::for_each()'s signature

utils/zerovec/src/zerovec/mod.rs Outdated Show resolved Hide resolved
utils/zerovec/src/zerovec/mod.rs Show resolved Hide resolved
/// })?;
///
/// assert_eq!(zerovec.to_vec(), &[212, 282, 422, 462]);
/// # Ok::<(), ()>(())
Copy link
Member

Choose a reason for hiding this comment

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

what is this line for? Is this to make the ? operator work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It's not shown in the docs, just makes the doctest run

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Now you've convinced me that make_mut is better, but I'll approve

@Manishearth Manishearth merged commit 47f667e into unicode-org:main Sep 30, 2021
@Manishearth Manishearth deleted the zv-iter-mut branch September 30, 2021 21:24
robertbastian pushed a commit to robertbastian/icu4x that referenced this pull request Oct 4, 2021
* Add ZeroVec::iter_mut()

* Add ZeroVec::for_each_mut()

* Expose make_mut, remove iter_mut, expose try_for_each_mut

* Update utils/zerovec/src/zerovec/mod.rs

Co-authored-by: Shane F. Carr <[email protected]>

* apply suggestion

* make_mut -> to_mut

* fix

Co-authored-by: Shane F. Carr <[email protected]>
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.

3 participants