faern / oneshot

Oneshot Rust channel working both in and between sync and async environments
Apache License 2.0
80 stars 9 forks source link

Add into_raw() / from_raw() methods #28

Closed bendk closed 1 year ago

bendk commented 1 year ago

Would you be open to adding into_raw() and from_raw() methods to convert between Sender/Receiver values and raw pointers? I think *mut () is correct, but any raw pointer is fine.

AFAICT, the underlying structs just store a pointer from Box::into_raw so this should be an easy to code. I could probably open a PR if needed. However, this does restrict what you can do with the structs in the future.

Use case: I'm a dev on the UniFFI project which generates FFI bindings for foreign languages. I'm testing out using oneshot for async callback interface methods and so far it's working great, except when passing Sender across the FFI as a raw pointer. My current code uses an extra Box, which isn't ideal given that Sender is already a wrapper around a leaked box pointer.

faern commented 1 year ago

I can't currently see any reason why from/into raw would be bad. I understand your use case and double boxing seem not ideal indeed!

Please submit a PR and we can discuss it from there

faern commented 1 year ago

Fixed in #29 and released as version 0.1.6