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 (2)

  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.