Skip to content

Commit 868b895

Browse files
committed
Updates for 1.0
1 parent 382e65a commit 868b895

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

docs/arrays.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let s = cx.string("hello!");
3535

3636
a.set(&mut cx, 0, s)?;
3737

38-
let v = a.get(&mut cx, 1)?;
38+
let v: Handle<JsValue> = a.get(&mut cx, 1)?;
3939
```
4040

4141
This is equivalent to the JavaScript code:
@@ -71,8 +71,8 @@ array[len] = value;
7171
An iterable Rust data structure such as `Vec` can be converted to a JavaScript array by looping over the elements. The [`JsArray::new()`](https://docs.rs/neon/latest/neon/types/struct.JsArray.html#method.new) method can be used to preallocate enough capacity for the number of elements.
7272

7373
```rust
74-
fn vec_to_array<'a, C: Context<'a>>(vec: &Vec<String>, cx: &mut C) -> JsResult<'a, JsArray> {
75-
let a = JsArray::new(cx, vec.len() as u32);
74+
fn vec_to_array<'cx, C: Context<'cx>>(vec: &Vec<String>, cx: &mut C) -> JsResult<'cx, JsArray> {
75+
let a = JsArray::new(cx, vec.len());
7676

7777
for (i, s) in vec.iter().enumerate() {
7878
let v = cx.string(s);

docs/example-projects.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Neon is used to power a growing community of applications and libraries—maybe
88

99
## Applications
1010

11-
- **[1password:](https://dteare.medium.com/behind-the-scenes-of-1password-for-linux-d59b19143a23)** Secure password manager
11+
- **[1Password:](https://dteare.medium.com/behind-the-scenes-of-1password-for-linux-d59b19143a23)** Secure password manager
1212
- **[Signal:](https://github.com/signalapp/libsignal-client)** Secure, private messaging
1313
- **[Finda:](https://keminglabs.com/finda/)** Type stuff, find things. No mousing.
1414
- **[Parsify Desktop:](https://parsify.app)** Extendable notepad calculator for the 21st Century.
@@ -25,8 +25,4 @@ Neon is used to power a growing community of applications and libraries—maybe
2525

2626
And <a href="https://github.com/search?q=path%3Apackage.json+cargo-cp-artifact&type=code" target="_blank">many more!</a>
2727

28-
## Rust Libraries
29-
30-
- **[neon-serde:](https://crates.io/crates/neon-serde2)** Easily convert between Rust and JavaScript datatypes
31-
3228
Want to add a project to this list? [Submit a PR](https://github.com/neon-bindings/website)!

docs/hello-world.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ The first thing to notice about this layout is that **a Neon project is both a N
3333

3434
The Rust source lives in `src/`, but JavaScript that augments Rust can live side-by-side.
3535

36-
Similar to how [Babel](https://babeljs.io/) can be adjusted to target a minimum JavaScript version, Neon can target a Node version by adjusting the `napi` feature in the `Cargo.toml`. By default, `npm init neon` will use the currently installed Node version.
36+
Similar to how [Babel](https://babeljs.io/) can be adjusted to target a minimum JavaScript version, Neon can target a Node version by adjusting the `napi` feature in the `Cargo.toml`. By default, `npm init neon` will use the latest stable Node-API version. Overriding:
3737

3838
```toml
3939
[dependencies.neon]
40+
default-features = false
4041
features = ["napi-6"]
4142
```
4243

docs/objects.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ First let's look at the signature of `Book::to_object()`, which we define as a m
6363

6464
```rust
6565
impl Book {
66-
fn to_object<'a>(&self, cx: &mut FunctionContext<'a>) -> JsResult<'a, JsObject> {
66+
fn to_object<'cx>(&self, cx: &mut FunctionContext<'cx>) -> JsResult<'cx, JsObject> {
6767
// ...
6868
}
6969
}
7070
```
7171

72-
This is our first example using a _[lifetime annotation](https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html)_ `'a`. This allows the Rust compiler to ensure that our code never accidentally makes an unsafe reference to JavaScript values managed by the Node runtime. Specifically, this signature tells Neon that the result object returned by this function (which has lifetime `'a`) is managed by the runtime context that was passed in as an argument (which also has that same lifetime `'a`).
72+
This is our first example using a _[lifetime annotation](https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html)_ `'cx`. This allows the Rust compiler to ensure that our code never accidentally makes an unsafe reference to JavaScript values managed by the Node runtime. Specifically, this signature tells Neon that the result object returned by this function (which has lifetime `'cx`) is managed by the runtime context that was passed in as an argument (which also has that same lifetime `'cx`).
7373

7474
If you've never seen lifetimes before or are not yet confident using them, don't worry! For now, you can use this code as a template, and know that the Rust compiler will keep you safe.
7575

7676
Now here is the full implementation:
7777

7878
```rust
79-
fn to_object<'a>(&self, cx: &mut FunctionContext<'a>) -> JsResult<'a, JsObject> {
79+
fn to_object<'cx>(&self, cx: &mut FunctionContext<'cx>) -> JsResult<'cx, JsObject> {
8080
let obj = cx.empty_object();
8181

8282
let title = cx.string(&self.title);
@@ -99,7 +99,7 @@ One thing worth noticing about this function is that it doesn't use anything spe
9999

100100
```rust
101101
impl Book {
102-
fn to_object<'a>(&self, cx: &mut impl Context<'a>) -> JsResult<'a, JsObject> {
102+
fn to_object<'cx>(&self, cx: &mut impl Context<'cx>) -> JsResult<'cx, JsObject> {
103103
// same as before...
104104
}
105105
}

docs/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Neon requires Node.js and supports **the latest Node version and all LTS release
1212

1313
## Install Rust
1414

15-
Neon requires Rust for development. If you don't already have Rust installed, or don't have a supported version, go to the [Rust web site](https://www.rust-lang.org/install.html) for installation instructions.
15+
Neon requires Rust for development. If you don't already have Rust installed, or don't have a supported version, go to the [Rust web site](https://www.rust-lang.org/) for installation instructions.
1616

1717
Rust may have additional dependencies depending on your target platform (for example, Visual Studio on Windows).

src/pages/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import "../css/bootstrap.css";
1515
const jsExample = `
1616
// JavaScript
1717
function hello() {
18-
let result = fibonacci(10000);
18+
let result = fibonacci(75);
1919
console.log(result);
2020
return result;
2121
}
@@ -24,8 +24,8 @@ function hello() {
2424
const neonExample = `
2525
// Neon
2626
fn hello(mut cx: FunctionContext) -> JsResult<JsNumber> {
27-
let result = fibonacci(10000);
28-
println!("{}", result);
27+
let result = fibonacci(75);
28+
println!("{result}");
2929
Ok(cx.number(result))
3030
}`.trim();
3131

0 commit comments

Comments
 (0)