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

feat(neon): Add more TryIntoJs and TryFromJs implementations #1066

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Sep 17, 2024

While trying #[neon::export] out in another project, I found some trivial TryFromJs and TryIntoJs implementations that simplified code.

  • TryFromJs for Root<T>. We can call .root(cx) when extracting
  • TryIntoJs for Box<T> and Arc<T> smart pointers. This is especially useful if you want to return an Arc<Vec<T>> and convert it into a typed array.
  • TryIntoJs for &Vec<T> and &String. We already had the slice versions, but it's nice to have these as well when combined with the smart pointers above.

I wanted to implement for T where T: AsRef<U> and for<'a> &'a U: TryIntoJs<'cx>, but this isn't possible since U wouldn't be bound by the implementation. It also conflicts with some specialized versions.

There's a bunch more that we could add (e.g., Box<str>), but I'm trying to be a little conservative and not implement for a bunch of strange types that users don't need. These are all convenience implementations anyway. Users have With as an escape hatch.

@kjvalencik kjvalencik requested a review from dherman September 17, 2024 14:07
@kjvalencik kjvalencik force-pushed the kv/extract-types branch 2 times, most recently from f2d803b to eb28eca Compare September 19, 2024 14:17
@kjvalencik kjvalencik changed the base branch from main to kv/clippy September 19, 2024 21:27
@kjvalencik kjvalencik changed the base branch from kv/clippy to main September 19, 2024 21:27
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 is super nice. 🚢 it!

@kjvalencik kjvalencik merged commit ffb3f99 into main Sep 20, 2024
9 checks passed
@kjvalencik kjvalencik deleted the kv/extract-types branch September 20, 2024 16:44
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