Unofficial Hacker News client - receive Push Notifications on replies.

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

206 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 (5)

  1. 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.

          Replies (1)
          1. That's six, which is hardly dozens. All of the examples you gave aren't allocator aware. They will reject a Vec<T,Goose> unless Goose is actually the Global allocator. Even if Goose is equivalent by Rust's allocator rules that's not good enough, the type matching wants an exact match not just allocator equivalence.

            And this makes some sense because Vec<T,Global> has properties they may care about since they're the new owners of this Vec, they don't want a Vec<T,Goose> which might have very different ideas about allocation.

            As your parent says, most APIs care about slices and thus do not communicate an allocator, so they're agnostic to allocation.