Unofficial Hacker News client - receive Push Notifications on replies.

The state of Rust allocators in 2026: stabilised (opens external site)

210 points by fanf2 2 days ago | cetra3.github.io | 85 comments on HN | Vote on HN (opens Hacker News)

View full thread · View on Hacker News

Comment thread (8)

  1. Yet, in the lang adoption game, many who were looking at Zig thanks to native support for allocators will now re-look at Rust to solve their problem.
    Replies (1)
    1. And many who said they'd never use custom allocators when discussing using Zig will see how neat it is now that they can do it in Rust.
      Replies (2)
      1. Maybe. I don't expect this feature to have wide appeal. It's not useless, there are cases where you want this and it's great that it stabilized, but I think they're not very common and so in most cases as with everything else you shouldn't do this until you've got a problem it can solve.
      2. People have been able to do this in Rust for longer than Zig has existed. What this new development brings is a standardized interface to streamline interoperability, not any new language capability. The bumpalo crate has been the standard bearer here for nearly a decade now, currently counting 778 million downloads on crates.io.
        Replies (1)
        1. Without standardized interfaces, custom allocators have limiteduse. bumpalo could only be used seamlessly with its own custom types (like bumpalo::collections::Vec or bumpalo::boxed::Box.

          bumpalo::collections::Vec<'bump, T> is a completely distinct type from std::vec::Vec<T>. You cannot pass an arena-allocated Vec or String to third-party libraries that expect standard library types without copying or converting them to slices first

          Replies (1)
          1. > You cannot pass an arena-allocated Vec or String to third-party libraries that expect standard library types without copying or converting them to slices first

            Slices are already the standard for interoperability between Rust libraries, and always have been. There may very well be libraries out there whose APIs expect you to pass Vecs into them, but that would be highly atypical.

            Replies (1)
            1. > There may very well be libraries out there whose APIs expect you to pass Vecs into them, but that would be highly atypical.

                  arrow       Buffer::from_vec(Vec<T>)
                  ndarray     Array::from_vec(Vec<T>)
                  ndarray     Array::from_shape_vec(shape, Vec<T>)
                  bytes       Bytes::from(Vec<u8>)
                  reqwest     Body::from(Vec<u8>)
                  serde_json  Value::Array(Vec<Value>)
               
              Dozens of example of very popular rust libraries. Usage is regular, not atypical. The slice variants generally require allocating and copying data or produces a borrowed object. Ownership transfer without copying is a problem.

              allocator-aware APIs can enable zero-copy ownership transfer across library boundaries, even when the memory was allocated using a custom allocator. This is wowza power.

              Continue this thread (1 replies) →