Skip to content

Support associated methods #51

Closed
Closed
@dtolnay

Description

@dtolnay

Currently only freestanding functions are supported by this crate, not methods.

I like the approach of using self in the foreign function parameter list to signify a method receiver:

#[cxx::bridge]
mod ffi {
    extern "C" {
        type C;
        fn f(self: &C);
    }

    extern "Rust" {
        type R;
        fn g(self: &R);
    }
}

struct R {...}

impl R {
    fn g(&self) {...}
}

This would expose the methods r.g() to C++ and c.f() to Rust.

The above syntax would require rustc 1.43 or newer for rust-lang/rust#68728.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions