2 ms·
> creating a closure that references a variable outside of its scope is not simple Well sure, but how often do you need to do that in a web API endpoint handle
by nicoburns 6y ago
> creating a closure that references a variable outside of its scope is not simple
Well sure, but how often do you need to do that in a web API endpoint handler? In my experience: not often at all. Rust can be hard, but generally isn't for this use case.
> You can make your life a lot easier by wrapping everything you reuse in Rc<> to make it reference counted, but then you're eating into the performance gains that are the initial selling point
Frameworks like Rocket or Actix-web will handle this for you. In my experience it doesn't tend to affect performance that much. Remember: Node is single-threaded. Multi-threaded + atomics + optimised compiled code is still significantly faster.