extern "Rust" {
type Foo; // Some opaque type managed by rust
fn create_foo() -> Box<Foo>; // C++ gets a reference to Foo
fn do_something_with_foo(foo: Box<Foo>) -> Result<i32>; // C++ gives back ownership of Foo to rust at a later time
}
The above code compiles fine, but I'm not sure if it should. This is because the generated code looks like this:
The parameter signature doesn't make sense to me, because I would expect it to take foo by rvalue reference, that way I can call do_something_with_foo(std::move(boxed_foo)) and value gets moved into the function, and cleaned up by rust. As it stands now, I can never use this function, because foo can never be copied or created, so it can never be called. Is this expected behavior? If yes, then how would this be useful?
Suppose that I create the following interface:
The above code compiles fine, but I'm not sure if it should. This is because the generated code looks like this:
The parameter signature doesn't make sense to me, because I would expect it to take foo by rvalue reference, that way I can call
do_something_with_foo(std::move(boxed_foo))
and value gets moved into the function, and cleaned up by rust. As it stands now, I can never use this function, because foo can never be copied or created, so it can never be called. Is this expected behavior? If yes, then how would this be useful?