Rust for JavaScript Developers – Functions and Control Flow
I just converted a relatively simple node.js program to Rust (because the native libusb bindings for node.js crash immediately on Windows 7 64-bit)<p>Rust made me worry about a lot more than I wanted to. Threads, locking, mutability. What was 80 lines of:<p>1. open USB device, get handle<p>2. start a WebSocket server, accept clients<p>3. proxy incoming USB device traffic to all WebSocket clients<p>4. proxy incoming WebSocket traffic to USB device<p>in node.js turned into battles with dyn FnMut traits to pass "callback/event" handlers around, spawning threads to not block on libusb reading / WebSocket client reading, borrowing, cloning, mutex locking, reference counting with Rust like you can in JavaScript.<p>You can't just "move variables from one scope into callback/lambda" scope with any sort of ease in Rust.