-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Arc<Self> ? #282
Comments
This should work, use std::sync::Arc;
pub struct Foo1;
impl Foo1 {
fn bar(&self) {}
fn bar2(&self) {}
}
foreign_class!(class Foo1 {
self_type Foo1;
constructor Foo1::new() -> Arc<Foo1> {
Arc::new(Foo1)
}
fn Foo1::bar(&self);
fn Foo1::bar2(&self);
}); |
Sorry I didn't do a very good example. My issue is when I'm trying to have the actual Rust struct Foo;
impl Foo {
// this fn needs to be able to copy a strong ref to itself
fn bar_by_arc(self: Arc<Self>) {}
}
foreign_class!(class Foo {
// ...
// none of these work:
fn Foo::bar_by_arc(&self);
fn Foo::bar_by_arc(self: Arc<Self>);
}); Obviously one workaround is to do it with a free function: fn bar_by_arc(foo: Arc<Foo>) {
// logic that would go inside foo::bar_by_arc in here instead
} related: https://stackoverflow.com/a/25463033 |
Workaround is a little stranger actually, because on C++ side it wants to consume Foo f;
Foo::bar_by_arc(f); // error: copy ctor is deleted Instead I return a new foreign_class!(class Foo {
fn bar_by_arc(foo: &Arc<Foo>) -> Arc<Foo> {
// keep a copy for returning
let ret_foo = Arc::clone(&foo);
// copy the ref so Foo can work with it
let foo = Arc::clone(&foo);
foo.bar_by_arc();
ret_foo
}
}) Then on C++ side: Foo f;
f = Foo::bar_by_arc(std::move(f));
// now i can keep my `f` |
|
Title of issue #20 suggests this was fixed but I can't seem to get it to work or find it in your test cases :)
The text was updated successfully, but these errors were encountered: