Slide 1

Slide 1 text

N E O N R U S T + N O D E =

Slide 2

Slide 2 text

A whole new generation of systems programmers…

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

• Dip your toe in • Performance • Easy integration of native libraries • Hack without fear: safety first!

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

#[macro_use] extern crate neon; use /* ... */; fn hello(call: Call) -> JsResult { Ok(JsString::new(call.scope, "hello node").unwrap()) } register_module!(m, { m.export("hello", hello) });

Slide 10

Slide 10 text

#[macro_use] extern crate neon; use /* ... */; fn hello(call: Call) -> JsResult { Ok(JsString::new(call.scope, "hello node").unwrap()) } register_module!(m, { m.export("hello", hello) }); ?

Slide 11

Slide 11 text

init_obj init_prop set_prop initObject eventHandler JavaScript Rust Object::set setter V8 GC'ed Heap JavaScript

Slide 12

Slide 12 text

init_obj init_prop set_prop initObject eventHandler JavaScript Rust Object::set setter V8 GC'ed Heap JavaScript

Slide 13

Slide 13 text

init_obj init_prop set_prop initObject eventHandler JavaScript Rust Object::set setter V8 GC'ed Heap JavaScript

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

var total = 0; for (var i = 0, n = lines.length; i < n; i++) { total += wcLine(lines[i], "thee"); }

Slide 16

Slide 16 text

function wcLine(line, search) { var words = line.split(' '); var total = 0; for (var i = 0, n = words.length; i < n; i++) { if (matches(words[i], search)) { total++; } } return total; } 280ms

Slide 17

Slide 17 text

fn wc_line(line: &str, search: &str) -> i32 { let mut total = 0; for word in line.split(' ') { if matches(word, search) { total += 1; } } total } 85ms

Slide 18

Slide 18 text

fn wc_line(line: &str, search: &str) -> i32 { line.split(' ') .filter(|word| matches(word, search)) .fold(0, |sum, _| sum + 1) }

Slide 19

Slide 19 text

fn wc_line(line: &str, search: &str) -> i32 { line.split(' ') .filter(|word| matches(word, search)) .fold(0, |sum, _| sum + 1) } lines.into_iter() .map(|line| wc_line(line, search)) .sum()

Slide 20

Slide 20 text

fn wc_line(line: &str, search: &str) -> i32 { line.split(' ') .filter(|word| matches(word, search)) .fold(0, |sum, _| sum + 1) } lines.into_par_iter() .map(|line| wc_line(line, search)) .sum() 50ms

Slide 21

Slide 21 text

fn wc_line(line: &str, search: &str) -> i32 { line.split(' ') .filter(|word| matches(word, search)) .fold(0, |sum, _| sum + 1) } lines.into_par_iter() .map(|line| wc_line(line, search)) .sum() 50ms

Slide 22

Slide 22 text

let mut buffer = call.arguments.require(scope, 0)? .check::()?; let total = buffer.grab(|data| { let corpus = str::from_utf8(data.as_slice()).unwrap(); wc(&lines(corpus), "thee") }); Ok(JsInteger::new(scope, total))

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

struct Greeter { greeting: String } declare_types! { pub class JsGreeter for Greeter { init(greeting: String) { Ok(Greeter { greeting: greeting }) } method hello(call: Call) { let scope = call.scope; let name = call.arguments.require(scope, 0)?.check::()?; let message = call.arguments.this(scope).grab(|greeter| { format!("{}, {}!", greeter.greeting, name) }); Ok(JsString::new(scope, message).unwrap()) } } }

Slide 25

Slide 25 text

module! { export class JsGreeter for Greeter { init(greeting: String) { Ok(Greeter { greeting: greeting }) } method hello(name: String) -> String { Ok(self.arguments.this(self.scope).grab(|g| { format!("{}, {}!", g.greeting, name) })) } } }

Slide 26

Slide 26 text

module! { export function add1(x: i32) -> i32 { Ok(x + 1) } }

Slide 27

Slide 27 text

A few caveats: • Currently better for apps than libs. • Calling from JS to Rust costs, so make it worth it. • I keep falling asleep in my comfy hacking chair!

Slide 28

Slide 28 text

https://github.com/rustbridge/neon Thank you!

Slide 29

Slide 29 text

I M A G E C R E D I T S • https://unsplash.com/photos/Niy6KKRAu1Y • https://www.youtube.com/watch?v=N1icEHtgb3g • http://www.sideshowtoy.com/collectibles/the-hobbit-gandalf-the-grey-asmus-collectible-toys-902681/ • https://www.rust-lang.org/logos/rust-logo-512x512-blk.png • https://nodejs.org/static/images/logos/nodejs-new-white-pantone.png • https://www.flickr.com/photos/morgennebel/11854357125/in/photolist-j4wFnF-poSvWa-9F81pt-poCWZL-pwJLS8- o1WiLo-87zwv6-rEfLQD-9adjGY-g5WKTT-g5W4UA-psQtns-fddieS-rn4gXZ-pnjo8R-e9Ck2i-kD5gZX-CCXFqE-eb6pxd- g5WniL-ey9Qs1-cJofsb-6vvL1M-nRgkhR-6edC3p-kHEzPp-4zYFsi-U7wt9-fJU62F-ssgkaY-qJehyN-kUfLJx-qLndLK- fiHPW7-ffAfAq-ieJcgA-ieJiDo-rcvDPd-e9CptH-pwJEX2-ieJgyo-cxR34J-cgc7pj-3dBYvj-eFBMJJ-9hEsh5-avugjT- cgc6Wm-ieHQLr-fHDYpN • http://www.anonymousproductionassistant.com/wp-content/uploads/2016/10/main_freereports.jpg • https://www.youtube.com/watch?v=jDQaIl_1Nfk • https://www.youtube.com/watch?v=8ud6haTTfFY • https://www.disneyclips.com/imagesnewb3/images/clipcindydream.gif