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): Node stdlib #1074

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

feat(neon): Node stdlib #1074

wants to merge 2 commits into from

Conversation

dherman
Copy link
Collaborator

@dherman dherman commented Sep 30, 2024

Experimental API for convenient access to the Node stdlib.

Examples:

use neon::node::Node;

// ...

cx.console().log("hello, world!")?;

// ...

let versions = cx.process().versions()?;
println!("node version: {}", &versions.data().node);

@dherman dherman changed the title Node stdlib feat(neon): Node stdlib Sep 30, 2024

// FIXME: when we land #1056, this can get simplified
// FIXME: msg should be a generic TryIntoJs
pub fn log(&mut self, msg: &str) -> NeonResult<()> {
Copy link
Member

@kjvalencik kjvalencik Sep 30, 2024

Choose a reason for hiding this comment

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

TryIntoJs will cover logging things that aren't string, but console.log(..) is also variadic. Thoughts on how we cover that? Could we use the TryIntoArguments trait?

It would be interesting to explore what a log macro would look like. 🤔 Something tricky in a macro is disambiguating between format arguments and distinct arguments to log.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here’s what my thinking was, but tell me what you think:

I was thinking, you can get the most general behavior from the JS values, but the goal here is convenient and idiomatic Rust syntax for the most common functionality. So I figure the highest value is getting the cx.console().log(x) syntax, and the variadic use case is less important.

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