logoalt Hacker News

kibwen • yesterday at 6:28 PM • 1 reply • view on HN

> 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

lenkite • yesterday at 7:56 PM

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

➕ show 1 reply