Skip to content
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

change(neon): Change TryIntoJs and TryFromJs accept Cx instead of being generic over Context #1062

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

kjvalencik
Copy link
Member

Being generic over Context offers no benefits over Cx. It is simpler to remove a generic argument.

  • Every Context derefs to Cx
  • Cx implements Context
  • Reduces code bloat from monomorphization

We should double check that there's no other new APIs introduced in the pre-release that could benefit from this change. Unfortunately, we can't change existing APIs without a breaking change.

…ng generic over Context

Being generic over `Context` offers no benefits over `Cx`. It is simpler to remove a generic argument.
* Every `Context` derefs to `Cx`
* `Cx` implements `Context`
* Reduces code bloat from monomorphization
Copy link
Collaborator

@dherman dherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

I noticed a handful of places in the API docs where there are examples of generic functions that take C: Context<'cx> (1, 2, 3). Should we change those to take a Cx now as well?

I also filed an issue for the website to change the guides to use the new Cx type once it gets published.

fn try_neon_export_return<C>(self, cx: &mut C) -> JsResult<'cx, JsValue>
where
C: Context<'cx>;
fn try_neon_export_return(self, cx: &mut Cx<'cx>) -> JsResult<'cx, JsValue>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such a quality of life improvement. Wow.

@kjvalencik
Copy link
Member Author

@dherman Great catch! Those are the only examples I saw that still unnecessarily used Context. I fixed them up. The great news is that 2 of the 3 are no longer generic at all! 🎉

@kjvalencik kjvalencik merged commit 63551b1 into main Sep 3, 2024
9 checks passed
@kjvalencik kjvalencik deleted the kv/concrete-try-js branch September 3, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants