Skip to content

Update code example in README #1109

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,11 @@ Neon supports Rust stable version 1.65 and higher. We test on the latest stable,
## A Taste...

```rust
fn make_an_array(mut cx: FunctionContext) -> JsResult<JsArray> {
// Create some values:
let n = cx.number(9000);
let s = cx.string("hello");
let b = cx.boolean(true);

// Create a new array:
let array = cx.empty_array();

// Push the values into the array:
array.set(&mut cx, 0, n)?;
array.set(&mut cx, 1, s)?;
array.set(&mut cx, 2, b)?;

// Return the array:
Ok(array)
}
const URL: &str = "https://jsonplaceholder.typicode.com/todos";

#[neon::main]
fn main(mut cx: ModuleContext) -> NeonResult<()> {
cx.export_function("make_an_array", make_an_array)?;
Ok(())
#[neon::export(json)]
async fn todos() -> Result<serde_json::Value, Error> {
Ok(reqwest::get(URL).await?.json().await?)
}
```

Expand Down
Loading