Skip to content
Discussion options

You must be logged in to vote

I think there are two issues: Passing files and passing I/O objects like BufferedReader (which also manage an internal buffer).

If you are able to avoid the BufferedReader layer, you could pass file descriptors which are basically integers to Rust and use File::from_raw_fd.

Otherwise, you could just take &PyAny and assume that it has a read Python method which you can call via PyAny::call1. You could then try to implement a custom wrapper like

struct PyReader<'a>(&'a PyAny);

impl Read for PyReader<'_> { ... }

which would however imply quite a bit of overhead to copy the bytes return by the Python read into the &mut [u8] buffer passed into the Rust read.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@wiktor-k
Comment options

@adamreichold
Comment options

@wiktor-k
Comment options

Answer selected by wiktor-k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants