Bridging callbacks and futures

⚓ Rust    📅 2025-09-30    👤 surdeus    👁️ 4      

surdeus

Let's say I have a low-level C API that exposes a callback-based operation:

struct Widget;

void foo(*Widget widget, void* context, void (*callback)(void*, int32_t))

The contract is that callback is invoked later, on a different thread. What is the most idiomatic way to convert that API to Futures, preferably using only stdlib?

struct Widget {
  c: *mut c::Widget
}

impl Widget {
    pub async fn foo(&mut self) i32 {
        ...
    }
}

3 posts - 3 participants

Read full topic

🏷️ Rust_feed