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): Allow getting a &'cx T from a Handle<'cx, JsBox<T>> #1087

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Jan 10, 2025

Resolves #678

I added Handle<JsBox>::as_inner and JsBox::deref. Let me know if you have preferred names. I was trying to pick reasonable names that didn't conflict with built-in incompatible traits (e.g., AsRef).

This feature is needed for impl<'cx, T> TryFromJs<'cx> for &'cx RefCell<T> which will allow low boilerplate extractors.

@kjvalencik kjvalencik requested a review from dherman January 10, 2025 22:36
@dherman
Copy link
Collaborator

dherman commented Jan 10, 2025

I added Handle<JsBox>::as_inner and JsBox::deref.

Oh, I like these names!

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.

Love it. I left a small copy edit for the comments.

/// See also [`JsBox::deref`].
pub fn as_inner(&self) -> &'cx T {
// # Safety
// JS values associated with an in-scope `Context` *cannot* garbage collected. This
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// JS values associated with an in-scope `Context` *cannot* garbage collected. This
// JS values associated with an in-scope `Context` *cannot* be garbage collected. This

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.

Handle<'a, JsBox<T>> should be able to be dereferenced to &'a T
2 participants