dtolnay/cxx

Extern "Rust" types that are nonlocal

Open

#496 opened on Nov 22, 2020

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Rust (253 forks)batch import
help wanted

Repository metrics

Stars
 (4,472 stars)
PR merge metrics
 (Avg merge 8m) (3 merged PRs in 30d)

Description

The following worked prior to 1.0:

type DataSourcePrivate = Rc<DataSource>;

#[cxx::bridge(namespace = "mcrtlib::ffi")]
mod types {
    pub struct DataSource {
        pub inner: Box<DataSourcePrivate>,
    }

    extern "Rust" {
        type DataSourcePrivate;

        // ...
    }
}

However, now I just get a

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
  --> library/src/ffi.rs:85:9
   |
85 |         type DataSourcePrivate;
   |         ^^^^^-----------------
   |         |    |
   |         |    `Rc` is not defined in the current crate
   |         impl doesn't use only types from inside the current crate
   |
   = note: define and implement a trait or new type instead

Is it possible to make this work again or should I wrap my Rc in a tuple struct?

Contributor guide