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)Rust made me worry about a lot more than I wanted to. Threads, locking, mutability. What was 80 lines of:1. open USB device, get handle2. start a WebSocket server, accept clients3. proxy incoming USB device traffic to all WebSocket clients4. proxy incoming WebSocket traffic to USB devicein 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.You can't just "move variables from one scope into callback/lambda" scope with any sort of ease in Rust.