How can I write a binding to a C function that expects an open file handle in Rust?

I used to play with writing libraries in Rust, and it was not difficult. Now, however, I'm stuck: I'm trying to write a binding for librsync , and some of its functions expect you to pass an open file descriptor (a FILE* in C).

For primitive types, there is an easy way to pass them to C (the same for pointers to primitive types). And, more clearly, I know that the libc box implements fopen , which in turn gives me mut FILE* (which will eventually complete the task). However, I was wondering if there is anything in the Rust standard library that gives me FILE* to switch to librsync - maybe something analogous with std::ffi::CString .

+5
source share
1 answer

Of course you can use RawFd , transmute and call libc::funcs::posix88::stdio::fdopen(_, mode) . That would be very incapable, though.

+1
source

All Articles