Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Rust All Hands 2019: Array iterators, Rayon, and more

March 22, 2019
Josh Stone
Related topics:
Developer tools
Related products:
Developer Toolset

    A few weeks ago, I had the pleasure of attending the second annual Rust All Hands meeting, hosted by Mozilla at their Berlin office. The attendees were a mix of volunteers and corporate employees covering the full range of Rust development, including the compiler, language, libraries, docs, tools, operations, and community. Although I’m sure there will be an official summary of the meeting (like last year’s), in this article, I'll cover a few things I was directly involved in. First, I'll look at a feature many developers have wanted for a long time...

    Array Iterators

    Idiomatic Rust code will make heavy use of the Iterator trait, but unfortunately this doesn’t work for arrays. This trait is not just a library feature but is also baked into the compiler, as even the plain for loop uses IntoIterator to convert its input, then calling Iterator::next() for each cycle of the loop. However, [T; N] arrays do not implement IntoIterator by value, so the best you can do is iterate it as a slice by reference (iter() and iter_mut()), or put your values in a Vec<T> on the heap instead to iterate by value. It’s also possible to iterate an array directly using a third party wrapper like ArrayVec, but this functionality really ought to be native in the standard library.

    for s in ["abc", "foo", "xyz"] {} // Nope, can't iterate a simple array by value
    for &s in &["abc", "foo", "xyz"] {} // It's OK by reference instead.
    
    let words: Vec<_> = my_string.split_whitespace().flat_map(|word| {
        // Can't return a temporary array for iteration at all
        [word.to_lower(), word.to_upper()]
    }).collect();

    I first tried to implement IntoIterator for arrays in PR32871. This wasn’t too hard technically, but the lack of constant generics made it a bit awkward. We don’t have a way to implement[T; N] for any N length, so at the moment traits are only implemented for lengths 0 through 32. The more unfortunate part is that this showed up in the iterator type signature too. While we would like it to be something like array::IntoIter<T, N>, without const generics I could only make this IntoIter<T, A> with a constraint that A must implement an internal FixedSizeArray trait. The libs team really didn’t want to commit to this, so that PR was closed.

    Later, Rust did approve RFC2000 for const generics, so I opened a new PR49000 for array iterators. (What nice round numbers!) We still didn’t have const generics implemented, but I argued for a path forward: add IntoIterator without stabilizing the array::IntoIter type, and we could clean that up in the near future. This seemed acceptable except for one more sticky issue, which was breaking the method resolution of existing .into_iter() calls. Currently, because arrays don’t directly have that method, such calls will auto-reference into a slice iterator. Adding the array IntoIterator will disrupt this into a value iterator. Clippy PR3344 added a lint for code that would be broken here, but we still want to proceed very carefully because these cases appear to be common. Clippy even had to change a few calls to .iter() in its own code in that PR!

    That’s much ado to bring us to the All Hands, where I came into the libs meeting with a hopeful solution. The idea we had toward the end of PR49000 was that we could add a new inherent method to arrays, preserving the current behavior for method resolution. The compiler prioritizes inherent methods over trait methods, but we would still get the benefit of the new IntoIterator for arrays by value in for loops, chain, flat_map, etc., where the trait method is called explicitly. We could also add a deprecation message on this inherent method to suggest using slice iter() instead. Although adding this inherent method would need some compiler lang help, the libs team was enthusiastic about this approach, and we announced this success at the All Hands end-of-day summary.

    // Here's the inherent method. (demonstrating with full const generics)
    impl<T, const N: usize> [T; N] {
        #[deprecated(note = "use slice `iter()` to iterate by reference)]
        fn into_iter(&self) -> slice::Iter<'_, T> {
            self.iter()
        }
    }
    
    // Now the new trait impl can hide behind the inherent method.
    impl<T, const N: usize> IntoIterator for [T; N] {
        type Item = T;
        type IntoIter = IntoIter<T, N>;
        fn into_iter(self) -> Self::IntoIter {
            // ...
        }
    }

    If you’re more familiar with Rust’s method resolution, you may already see the problem with this approach, which I realized the next day. We had experimented during the meeting with a placeholder struct A type to confirm the use of the inherent method, but we hadn’t properly covered all variations. When I expanded the example later, I found that no, an inherent into_iter(&self) does not actually take precedence over IntoIterator::into_iter(self) when called directly on an array value. The latter is found first because the method receiver is a direct self, whereas the former requires auto-referencing to call on &self. We must use a reference to borrow the array for slice::Iter, so it seems we don’t actually have a way to preempt IntoIterator here.

    Sadly, we had to revoke our previous announcement of success. Maybe we can still find a way to override method resolution in the compiler for this issue, if we’re willing to accept some language impurity here. Otherwise, we’re back to finding ways to lessen the pain of adding this new trait implementation. The first step is probably to promote that Clippy lint into the main compiler to give it more visibility, but even then we’ll probably want to leave that warning for a while before daring to make the actual change. If you’re using into_iter() on an array to get a slice iterator, please switch to iter() ASAP, and if you have ideas to ease this transition, please speak up!

    More at All Hands

    Another useful meeting was with the WebAssembly (Wasm) working group, where I represented Rayon—a crate providing a work-stealing threadpool and parallel iterators. We would love to get Rayon working with Wasm to enable that easy parallelism under JavaScript, but threading is still in an early state. Most of the std::thread implementation for Wasm is just stubbed out, so Rayon will hit errors as soon as it tries to start a threadpool. We talked about the limitations faced with threads that would want to wait on JavaScript promises but decided it would still be useful to have Rayon usable for CPU-bound workloads. We planned to add a custom way to start Rayon's threadpool where they can control the spawning, and I've since opened rayon PR636 for experimentation.

    Between several meetings on the build system and the infrastructure and release teams, we made plans to improve the experience for Rust contributors. In rustbuild, the bespoke tool for bootstrapping rustc itself, we discussed a few different contributor workflows and how we might reduce their burden. The plan is to more aggressively cache build artifacts that won't affect that contributor's goal and make it easier to use the build options for that path. The infrastructure team discussed the burden of CI in landing your pull request, because Rust requires a clean CI run before merging any change. A full run takes about 2.5 hours, and we talked about ways we could tweak the current CI runs to have less redundant testing, while still ensuring sufficient coverage. Finally, in the release team, we talked about adding more automation to aid issue triage and pull request management, such as a new bot to let anyone apply issue labels and one to automatically manage PR rollups to aggregate CI runs.

    Beyond the meetings in which I was actively involved, the Rust All Hands was also a great opportunity to learn more about what other teams are working on. Now that the 2018 edition has shipped in Rust 1.31, everyone can take a breath from the release crunch and start planning for the next few years. The compiler team discussed some potentially major refactoring that could enable better IDE integration and made plans to experiment toward that end. The lang team laid out a HUGE list of potential new features, from things that are almost ready to stabilize with a little polishing to pipe dreams that may have no real future in Rust at all. And, with several meeting rooms running simultaneously, I couldn't possibly catch it all. I hope other attendees will blog about their results and share more information.

    Last updated: February 6, 2024

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI