DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
434 stars 59 forks source link

[Request] Migration guide 0.1.7 -> 0.4-beta #180

Open richarddd opened 11 months ago

richarddd commented 11 months ago

First of all, thanks for an amazing library 🙌

Since a lot of changed between 0.1.7 and 0.4, would it be super useful if there was some sort of "MIGRATION.md" markdown file or other forms of documentation :)

I know its still a beta version and a pre-release and you've probably have lots of other priorities, but i think this would help a lot of users and may avoid a few how can i do this? issues (including mine).

Thanks

DelSkayn commented 11 months ago

I will write a guide once 0.4 releases, the beta is currently still missing a bunch of stuff and some API might change.

In the mean time I wrote an overview of all the changes in the PR #176. (Which I see you already noticed, but mentioning it for anyone else looking for some info.)

RReverser commented 11 months ago

Not sure if it's better to create a new issue but I'm having problems even upgrading from 0.1.7 to 0.3.1 (latest stable).

I managed to figure out some of them - e.g. that getter (#[quickjs(get)]) can't take self by ownership anymore and only works with &self now (is that intended change or a regression? raised https://github.com/DelSkayn/rquickjs/issues/197 separately just in case) - but some others I'm stuck with and not sure what it wants.

Reduced example:

use rquickjs::{bind, Function, Value};

#[bind(object)]
mod bindings {
    use super::*;

    pub struct InvokeCallback;

    impl InvokeCallback {
        pub fn invoke_callback<'js>(&'js self, cb: Function<'js>) -> rquickjs::Result<Value<'js>> {
            cb.call(())
        }
    }
}

works from 0.1.7 to 0.2.2 inclusive, but fails with 0.3.0+ with:

error[E0277]: the trait bound `SelfMethod<InvokeCallback, for<'js> fn(&'js InvokeCallback, rquickjs::Function<'js>) -> Result<rquickjs::Value<'js>, rquickjs::Error> {InvokeCallback::invoke_callback}>: AsFunction<'_, _, _>` is not satisfied
   --> src/lib.rs:3:1
    |
3   | #[bind(object)]
    | ^^^^^^^^^^^^^^^ the trait `AsFunction<'_, _, _>` is not implemented for `SelfMethod<InvokeCallback, for<'js> fn(&'js InvokeCallback, rquickjs::Function<'js>) -> Result<rquickjs::Value<'js>, rquickjs::Error> {InvokeCallback::invoke_callback}>`
    |
    = help: the following other types implement trait `AsFunction<'js, A, R>`:
              <SelfMethod<T, F> as AsFunction<'js, (T, A), R>>
              <SelfMethod<T, F> as AsFunction<'js, (T, A, B), R>>
              <SelfMethod<T, F> as AsFunction<'js, (T, A, B, D), R>>
              <SelfMethod<T, F> as AsFunction<'js, (T, A, B, D, E), R>>
              <SelfMethod<T, F> as AsFunction<'js, (T, A, B, D, E, G), R>>
              <SelfMethod<T, F> as AsFunction<'js, (T, A, B, D, E, G, H), R>>
              <SelfMethod<T, F> as AsFunction<'js, (T,), R>>
    = note: required for `Func<(&str, SelfMethod<InvokeCallback, fn(&..., ...) -> ... {...::invoke_callback}>, ...)>` to implement `rquickjs::IntoJs<'_>`
    = note: the full type name has been written to '/home/rreverser/temp2/target/debug/deps/temp2-a8a094a42660467a.long-type-12038371161112787971.txt'
note: required by a bound in `rquickjs::Object::<'js>::set`
   --> /home/rreverser/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rquickjs-core-0.3.1/src/value/object.rs:121:37
    |
121 |     pub fn set<K: IntoAtom<'js>, V: IntoJs<'js>>(&self, key: K, value: V) -> Result<()> {
    |                                     ^^^^^^^^^^^ required by this bound in `Object::<'js>::set`
    = note: this error originates in the attribute macro `bind` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.

What does that mean / what changed? How do I fix it?

RReverser commented 11 months ago

Ok via long trial and error found that I now need to use &self instead of &'js self. I'm pretty sure I needed that explicit lifetime in the past, but if it works, I guess it's fine... I wish errors were somehow more descriptive, although not sure how that'd be achievable. Maybe migration guide will help with those issues at least.

Sytten commented 7 months ago

How are we feeling about 0.4? @DelSkayn I am still on a an between 0.3 version on our fork and I would very much like to get off of it. Anything you have in mind to get it over the finish line?

richarddd commented 7 months ago

How are we feeling about 0.4? @DelSkayn I am still on a an between 0.3 version on our fork and I would very much like to get off of it. Anything you have in mind to get it over the finish line?

I've been running 0.4 for quite some time now and it works very well. I would recommend using that until it goes out of beta

DelSkayn commented 7 months ago

I think the current beta is good enough for a full version. I mostly held of releasing a new version because I have been pretty busy. I will release a new version shortly.

Sytten commented 3 months ago

We need more examples, I am upgrading from an old commit I had tagged to 0.5 and I am lost. I will try to push something once I get back into it.