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

Update examples for v1.0 #97

Merged
merged 1 commit into from
Jan 29, 2024
Merged

Update examples for v1.0 #97

merged 1 commit into from
Jan 29, 2024

Conversation

kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Jan 29, 2024

We can make some further improvements when the args API lands.

@@ -9,3 +9,6 @@ members = [

[profile.release]
lto = true

[patch.crates-io]
neon = { git = "https://github.com/neon-bindings/neon.git" }
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to delete this once 1.0 is published.

let data = guard.get_mut();
let output = data.clone();
let output = JsUint8Array::from_slice(&mut cx, data)?;
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we were already cloning, we can get very similar ergonomics and performance by copying directly into the Uint8Array instead of using an external.

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.

Nice improvements!

@@ -135,7 +134,7 @@ impl Database {
let name = cx.argument::<JsString>(0)?.value(&mut cx);

// Get the `this` value as a `JsBox<Database>`
let db = cx.this().downcast_or_throw::<JsBox<Database>, _>(&mut cx)?;
let db = cx.this::<JsBox<Database>>()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

so nice

Copy link
Member Author

Choose a reason for hiding this comment

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

General specialization would be awesome here. We could have a blanket impl for downcasting T, but a specialized case for when T implements Value.

This would allow you to skip the JsBox here and assume it from an out param.

@kjvalencik kjvalencik merged commit 7a466b2 into main Jan 29, 2024
1 check passed
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