Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
Co-Authored-By: Michael Schmidt <[email protected]>
  • Loading branch information
daxpedda and RunDevelopment committed Dec 6, 2024
1 parent 9fc08b8 commit da0c13c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions guide/src/reference/static-js-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ extern "C" {
}
```

## Undeclared
## Optional statics

When accessing an in JS undeclared value, it will throw in JS. This can be accounted for by using `Option`.
If you expect the JavaScript value you're trying to access to not always be
available you can use `Option<T>` to handle this:

```rust
extern "C" {
Expand All @@ -82,7 +83,9 @@ extern "C" {
}
```

If `crypto` is undeclared in JS, it will simply return `None` in Rust.
If `crypto` is not declared or nullish (`null` or `undefined`) in JavaScript,
it will simply return `None` in Rust. This will also account for namespaces: it
will return `Some(T)` only if all parts are declared and not nullish.

## Static strings

Expand Down

0 comments on commit da0c13c

Please sign in to comment.