Gaynor: Buffers on the edge: Python and Rust

Post Syndicated from original https://lwn.net/Articles/912181/

Alex Gaynor examines the
awkwardness
that comes when trying to interface Python and Rust code.

The challenge is that if you want to pass some bytes to a Rust
library to parse them (or do any other processing for that matter),
the library almost certainly expects a &[u8], and
there’s no way to turn a &[ReadOnlyCell<u8>]
into a &[u8] safely, without allocating and
copying. And of course, the whole point of the Python buffer
protocol is to avoid these sorts of inefficiencies.

Therefore, the regrettable solution is that, right now, there is no
way to have all three of: efficiency, interoperability, and
soundness.