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 copying IntoIter implementation #1494

Open
Gaspard-- opened this issue Feb 25, 2025 · 0 comments
Open

Add copying IntoIter implementation #1494

Gaspard-- opened this issue Feb 25, 2025 · 0 comments

Comments

@Gaspard--
Copy link

Apologies if any terms aren't right, I'm still learning rust.

Currently, if you want to return an iterator consuming a temporary variable, you can't, because IntoIter is only implemented for &T and &mut T.

    // Works, because arrays implement IntoIter returning f32
    for x in (|| [0.0f32, 1.0f32].into_iter())() {
        print!("{}\n", x);
    }
    // Does not work, because nalgebra::Vector2 does not implement IntoIter returning f32, so the compiler picks &f32 instead
    for x in (|| Vector2::new(0.0f32, 1.0f32).into_iter())() {
        print!("{}\n", x);
    }

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e3c5472e96dbe560be70cf3c5e55c6b8

I was wondering if would possible to add the missing to implementation to support this? Is there some potential technical limitation I can't see?

Note that it's currently possible to work around this problem for very simple situations by chaining iterators over copies of each field.

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

No branches or pull requests

1 participant