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

Allow creating matrix iter with an owned view #1315

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

yotamofek
Copy link
Contributor

@yotamofek yotamofek commented Nov 12, 2023

Fixes #747

First of all - thanks for this crate, it's really fun to use, except for the lack of IntoIterator impls on (owned) view storages.

This allows overcoming the borrow checker issues when trying to do something like this:
image

Using the IntoIterator impl from this PR:
image

I implemented this feature by extracting a common subset of MatrixIter and MatrixIterMut into a RawIter struct which erases the lifetime it is created with, and iterates over raw pointers instead of references.
Then, the MatrixIter(Mut) structs become simple wrappers over RawIter, but with an added lifetime constraint.

It's technically possible to keep the old code (and remove most of the code added in this PR) and impl the new new_owned and new_owned_mut using a transmute from MatrixIter<'outer, ...> to a MatrixIter<'inner, ...>, but I'm not even sure that's not possibly UB.

Let me know what you think :)

@sebcrozet sebcrozet merged commit a91e3b0 into dimforge:dev Nov 12, 2023
10 of 12 checks passed
@sebcrozet
Copy link
Member

Thanks!

@yotamofek yotamofek deleted the owned-view-iter branch November 13, 2023 13:55
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.

Implement IntoIter for Matrix<N, R, C, S> where S: IntoIter, etc.
2 participants