randomPoison / cs-bindgen

Experiment in using Rust to build a library that can be loaded by Unity across multiple platforms
4 stars 0 forks source link

Expand Self when generating Rust bindings #24

Open randomPoison opened 4 years ago

randomPoison commented 4 years ago

Currently, cs-bindgen-macro doesn't do anything to expand Self when generating the binding code. This means that any usage of Self will result in a compiler error. For example, the following function:

#[cs_bindgen]
impl Foo {
    pub fn new() -> Self { ... }
}

Will generate the following binding:

#[no_mangle]
pub unsafe extern "C" fn __cs_bindgen_generated__Foo__new() -> <Self as IntoAbi>::Abi {
    IntoAbi::into_abi(Foo::new())
}

Since the generated binding is not in the context of an impl block, the usage of Self is no longer valid.

To fix this, the proc macro will need to detect usage of Self in a type position and replace it with the full type name.