Closed richarddd closed 1 year ago
Instead of taking the self instances as &self
you can retrieve the this value as its javascript object by taking it as This<Class<'js,Self>>
. You can return that object without any problems.
Any idea how would this be done using the new proc macro? :) Or do i need to manually implement the JsClass trait?
Example:
#[rquickjs::class]
#[derive(rquickjs::class::Trace)]
struct TestClass {
#[qjs(skip_trace)]
value: String,
}
#[rquickjs::methods]
impl TestClass {
#[qjs(constructor)]
pub fn new(value: String) -> Self {
Self { value }
}
pub fn append<'js>(this: This<Class<'js, Self>>, data: String) -> Class<'js, Self> {
this.0
}
}
the trait bound
__impl_append: JsClass<'js>
is not satisfied the following other types implement traitJsClass<'js>
: RustFunction<'js> TestClass
Also tried with:
pub fn append<'js>(self, data: String) -> Self {
self
}
Which results in:
the trait bound
rquickjs::function::This<TestClass>: FromParam<'_>
is not satisfied the traitFromParam<'js>
is implemented forrquickjs::function::This<T>
This seems to be a bug in the macro, It works if you use the resolved type instead of Self. So Class<'js, TestClass>
in the case of this example.
The macro doesn't replace Self with the right type when implementing IntoJsFunc for the method.
Should now be fixed in fd957b8.
Example:
self.into_js(ctx)
creates a new instance. How can i return the original one?