Skip to content

Commit 1c6f19b

Browse files
authored
Update README.md, include readme in crate docs (#321)
* Include README.md in docs * Fix syntax highlighting in README.md, ignore all readme codeblocks in doctests
1 parent 02dcd71 commit 1c6f19b

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Writing native node-js requires lots of boilerplate code. Node-bindgen generate
6868

6969
Install nj-cli command line, which will be used to generate the native library.
7070

71-
```
71+
```sh
7272
cargo install nj-cli
7373
```
7474

@@ -79,26 +79,26 @@ This is a one time step.
7979
Add two dependencies to your projects' ```Cargo.toml```.
8080

8181
Add ```node-bindgen``` as a regular dependency (as below):
82-
```
82+
```toml
8383
[dependencies]
8484
node-bindgen = { version = "6.0" }
8585
```
8686

8787
Then add ```node-bindgen```'s procedure macro to your build-dependencies as below:
88-
```
88+
```toml
8989
[build-dependencies]
9090
node-bindgen = { version = "6.0", default-features = false, features = ["build"] }
9191
```
9292

9393
Then update crate type to ```cdylib``` to generate node.js compatible native module:
94-
```
94+
```toml
9595
[lib]
9696
crate-type = ["cdylib"]
9797
```
9898

9999
Finally, add ```build.rs``` at the top of the project with following content:
100100

101-
```
101+
```rust,ignore
102102
fn main() {
103103
node_bindgen::build::configure();
104104
}
@@ -110,7 +110,7 @@ fn main() {
110110
Here is a function that adds two numbers. Note that you don't need to worry about JS conversion.
111111

112112

113-
```rust
113+
```rust,ignore
114114
115115
use node_bindgen::derive::node_bindgen;
116116
@@ -126,14 +126,14 @@ fn sum(first: i32, second: i32) -> i32 {
126126

127127
To build node.js library, using ```nj-cli``` to build:
128128

129-
```
129+
```sh
130130
nj-cli build
131131
```
132132

133133
This will generate Node.js module in "./dist" folder.
134134

135135
To build a release version:
136-
```
136+
```sh
137137
nj-cli build --release
138138
```
139139

@@ -169,7 +169,7 @@ undefined
169169

170170
## Function name or method can be renamed instead of default mapping
171171

172-
```rust
172+
```rust,ignore
173173
#[node_bindgen(name="multiply")]
174174
fn mul(first: i32,second: i32) -> i32 {
175175
first * second
@@ -181,7 +181,7 @@ Rust function mul is re-mapped as ```multiply```
181181
## Optional argument
182182

183183
Argument can be skipped if it is marked as optional
184-
```rust
184+
```rust,ignore
185185
#[node_bindgen]
186186
fn sum(first: i32, second: Option<i32>) -> i32 {
187187
first + second.unwrap_or(0)
@@ -195,7 +195,7 @@ Then sum can be invoked as
195195

196196
JS callback are mapped as Rust closure.
197197

198-
```rust
198+
```rust,ignore
199199
#[node_bindgen]
200200
fn hello<F: Fn(String)>(first: f64, second: F) {
201201
@@ -222,7 +222,7 @@ Callback are supported in Async rust as well.
222222

223223
Async rust function is mapped to Node.js promise.
224224

225-
```rust
225+
```rust,ignore
226226
227227
use std::time::Duration;
228228
use flv_future_aio::time::sleep;
@@ -252,7 +252,7 @@ addon.hello(5).then((val) => {
252252
Structs, including generic structs, can have have the to-JS conversion boilerplate autogenerated.
253253
Just apply the `node_bindgen` macro to your struct:
254254

255-
```rust
255+
```rust,ignore
256256
#[node_bindgen]
257257
struct MyJson {
258258
some_name: String,
@@ -285,7 +285,7 @@ Field names will be converted to camelCase.
285285

286286
Enums will also have their JS representation autogenerated with the help of `node_bindgen`:
287287

288-
```rust
288+
```rust,ignore
289289
#[node_bindgen]
290290
enum ErrorType {
291291
WithMessage(String, usize),
@@ -332,7 +332,7 @@ Generics and references are supported, with the same caveats as for structs.
332332

333333
JavaScript class is supported.
334334

335-
```rust
335+
```rust,ignore
336336
337337
struct MyClass {
338338
val: f64,
@@ -380,8 +380,8 @@ environment has a valid C/C++ compiler.
380380
In the future, this file will be re-written in Rust, removing this dependency.
381381

382382
Just make sure that you are compiling the rust module using
383-
```
384-
$ npx electron-build-env nj-cli build --release
383+
```sh
384+
npx electron-build-env nj-cli build --release
385385
```
386386

387387
otherwise you will get dreaded `A dynamic link library (DLL) initialization routine failed` when importing the rust module in electron
@@ -398,7 +398,7 @@ In addition, because `tslink` generates TypeScript types definitions, any change
398398

399399
For example,
400400

401-
```ignore
401+
```rust,ignore
402402
#[macro_use] extern crate tslink;
403403
use tslink::tslink;
404404
use node_bindgen::derive::node_bindgen;
@@ -426,7 +426,7 @@ impl MyScruct {
426426

427427
Would be represented (`*.d.ts`) as
428428

429-
```ignore
429+
```ts
430430
export declare class MyStruct {
431431
constructor(inc: number);
432432
incMyNumber(a: number): number;
@@ -441,11 +441,11 @@ Also, please **note**, `node-bindgen` by default applies snake case naming to me
441441

442442
File: `./Cargo.toml` (in a `root` of project):
443443

444-
```ignore
444+
```toml
445445
[project]
446-
...
446+
# ...
447447
[lib]
448-
...
448+
# ...
449449
[tslink]
450450
node = "./dist/index.node"
451451
```

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![doc = include_str!("../README.md")]
2+
13
#[cfg(feature = "node")]
24
pub mod core {
35
pub use nj_core::*;

0 commit comments

Comments
 (0)