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

Use <[_; N]>::each_ref() when available #121

Open
martinthomson opened this issue Oct 13, 2022 · 1 comment
Open

Use <[_; N]>::each_ref() when available #121

martinthomson opened this issue Oct 13, 2022 · 1 comment

Comments

@martinthomson
Copy link
Member

martinthomson commented Oct 13, 2022

There are a few places where we construct a fixed size array of objects, then run that through map() in order to produce another fixed size array. For example:

        let bit_ctx: [_; 3] = top_ctx
            .iter()
            .map(|ctx| ctx.narrow(&format!("bit{}", bit)))
            .collect::<Vec<_>>()
            .try_into()
            .unwrap();

This is super awkward as you have to iterate the slice, map, collect into a Vec<_>, then use try_into() to maybe create the array, then unwrap that. This would be cleaner, once each_ref() becomes available in mainline rust.

        let bit_ctx = top_ctx.each_ref().map(|ctx| ctx.refine(format!("bit{}", bit)));
@akoshelev
Copy link
Collaborator

Looks like things are moving to stabilization: rust-lang/rust#76118

rust-lang/rust#103522

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

2 participants