dtolnay / cxx

Safe interop between Rust and C++
https://cxx.rs
Apache License 2.0
5.68k stars 320 forks source link

cxx doesn't seem to support move self #1310

Closed boluoyu closed 5 months ago

boluoyu commented 5 months ago

Have the following code:

struct NetClient;

impl NetClient {

   fn start_run(self) {
       ...
    }
}

#[cxx::bridge]
pub mod ffi_rust_cpp {

     extern "Rust" {
            type NetClient;
             fn start_run(self); //error: unsupported method receiver
    }
}

What should I do?I need your help.

dtolnay commented 5 months ago

C++ does not have any equivalent for moving self into a member function call. There is no such thing as by-value this. You need to not use that in methods that need to be called from C++.