-
Notifications
You must be signed in to change notification settings - Fork 180
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
Add ZeroVec::iter_mut() #1128
Conversation
I elected to not make |
utils/zerovec/src/zerovec/mod.rs
Outdated
let mut aligned = T::from_unaligned(item); | ||
f(&mut aligned); | ||
*item = aligned.as_unaligned() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
/// })?; | ||
/// | ||
/// assert_eq!(zerovec.to_vec(), &[212, 282, 422, 462]); | ||
/// # Ok::<(), ()>(()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Co-authored-by: Shane F. Carr <[email protected]>
There was a problem hiding this 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
* 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]>
No description provided.