External executor for async Rust
This project aims to provide simple executor which helps to delegate running asynchronous Rust code to external event loops. As example, it may be useful in case when you develop dynamic linked libraries which have async code in Rust and want to run it in different execution environments.
Usage
On a Rust side you should add extern_executor
as dependency to your cdylib
crate and use spawn()
function to run futures, like so:
use spawn;
spawn;
On a C side you should implement executor's driver using your preferred event loop API. For example, when libuv is used it may looks like so:
static void
static void
static RustAsyncExecutorExternTask
static void
void
Now you can run your async code in libuv's event loop like so:
int
The C header rust_async_executor.h generated using cbindgen. There are two options how you can get it:
- Copy from include directory in this repo
- Generate by youself by using cbindgen feature
In second case generated header will be available at target/$PROFILE/include
directory.
Built-in event-loop drivers
To simplify setup for some widely used event loops the built-in drivers was introduced. To use driver you should enable corresponding feature. Currently supported next drivers:
- uv built-in libuv event loop integration (see example_uv)
- dart built-in dart-lang event loop integration (see example_dart)
Linking issues
Rust currently have an issues related to re-exporting of symbols from crate's dependencies (#2771).
As temporary solution you can setup build profile like so:
[]
= true
= false
Tokio compatibility
This executor incompatible with tokio's futures because tokio still has non-trivial executor which mixed with reactor.