ZettaScaleLabs / stabby

A Stable ABI for Rust with compact sum-types
Other
328 stars 13 forks source link

async example in docs outdated? #52

Closed kylezs closed 8 months ago

kylezs commented 8 months ago

I'm trying to use stabby to export a simple async function, however, there are no examples for this, and nor do the docs in the README seem to really work?

The code I have is just this:

use std::time::Duration;

use stabby::future::DynFuture;

#[stabby::export]
extern "C" fn entry_point() -> DynFuture<'static, stabby::result::Result<(), ()>> {
    stabby::boxed::Box::new(async move {
        println!("Executing shared1 entry point with new rust version!");

        tokio::time::sleep(Duration::from_millis(500)).await;

        Result::<(), ()>::Ok(())
    })
    .into()
}

and the error is:

error[E0308]: mismatched types
  --> shared1/src/lib.rs:9:5
   |
8  |   extern "C" fn entry_point() -> DynFuture<'static, stabby::result::Result<(), ()>> {
   |                                  -------------------------------------------------- expected `Dyn<'static, stabby::boxed::Box<()>, VtSync<VtSend<VTable<StabbyVtableFuture<stabby::stabby_abi::Result<(), ()>>>>>>` because of return type
9  | /     Box::new(async move {
10 | |         println!("Executing shared1 entry point with new rust version!");
11 | |
12 | |         tokio::time::sleep(Duration::from_millis(500));
13 | |
14 | |         Result::<(), ()>::Ok(())
15 | |     })
   | |______^ expected `Dyn<'_, Box<()>, VtSync<VtSend<VTable<StabbyVtableFuture<Result<(), ()>>>>>>`, found `Box<[async block@shared1/src/lib.rs:9:14: 15:6]>`
   |
   = note: expected struct `Dyn<'static, stabby::boxed::Box<()>, VtSync<VtSend<VTable<StabbyVtableFuture<stabby::stabby_abi::Result<(), ()>>>>>>`
              found struct `std::boxed::Box<[async block@shared1/src/lib.rs:9:14: 15:6]>`

Would be happy to add another simple example to /examples with an async export once I can get this working.

kylezs commented 8 months ago

Ok, seems the compiler was lying to me briefly... cargo clean seems to have resolved it