Skip to content

Implement the buffer protocol safely #657

@jimy-byerley

Description

@jimy-byerley

Hi !
I'm using rust as backend for a python module I'm working on, to get high performances on mesh operations. The data is owned by some rust Vecs but I would like to expose its content to python, to make possible extend the module with pure python (or at least to get some data points).

So I'm trying to implement the buffer protocol for my structs. I seen this page in pyo3. But it relies on pointers so it's unsafe.
But the buffer protocol is not incompatible with pyo3's safety since i read in the python doc that the memoryview object kept a hook on the viewed object

Is there a way to safely implement the buffer protocol for rust objects exposed by a #[pyclass] statement ?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions