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: teach BufferMut into_iter #1983

Closed
wants to merge 1 commit into from
Closed

Conversation

danking
Copy link
Member

@danking danking commented Jan 16, 2025

No description provided.

@danking danking requested a review from gatesn January 16, 2025 22:55
@danking danking marked this pull request as ready for review January 16, 2025 22:55
}
}

impl<T: Copy> IntoIterator for BufferMut<T> {
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor

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?

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@danking danking Jan 17, 2025

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.

Copy link
Contributor

@gatesn gatesn left a 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

@danking danking closed this Jan 17, 2025
@danking danking reopened this Jan 17, 2025
@danking danking closed this Jan 17, 2025
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