-
Notifications
You must be signed in to change notification settings - Fork 33
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: teach BufferMut into_iter #1983
Conversation
} | ||
} | ||
|
||
impl<T: Copy> IntoIterator for BufferMut<T> { |
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.
I would expect the into_iterator to actually consume the buffer instead of copying values
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.
otherwise you can make &T as a return value and the caller can copy
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.
I don't understand this, doesn't deref and derefmut give you &T and &mut T iterators already?
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.
you're correct that it would give you that but I didn't realize deref impls exist before making this comment
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.
I want this to compile:
let buf: BufferMut<T> = values.into_buffer_mut::<T>();
let mut new_buf: BufferMut<T> = BufferMut::<T>::with_capacity(buf.len() + 1);
new_buf.push(T::zero());
new_buf.extend(buf);
But it doesn't because buf
does not implement IntoIterator<Item = T>
. I somehow want to convince Rust to just memcpy the old buffer into the new buffer.
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.
You should check out how this is handled for Vec - spoiler alert, you want to be able to introspect passed iterator and extract the buffer back from it.
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.
I can punt on all of this and use a for loop because I need to increment each code by one anyway. Erm getting confused between codes and values.
EDIT: Let me look at the Vec implementation and get back to y'all.
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.
Could you add justification to the PR description?
I can believe this is needed, but I'm not quite sure of the use case to check if it's solvable already somehow
No description provided.