4 ms·
Embedding Rust in Ruby (with demo)
- voidlogic 14y agoI'm sure there are many Ruby programmers that are competent at low level code, but based on my anecdotal observations, I find the thought of the average Ruby developer writing Rust terrifying...
- pcwalton 14y agoI think it's a lot less terrifying than writing Ruby extensions in C (which has been the main alternative up to now), because Rust is memory-safe. There's a lot less that can go wrong when you can't scribble on freed memory or jump to undefined addresses outside of designated "unsafe { ... }" blocks. Note that the Gaussian blur function is all safe code—the only unsafe code here is the code to marshal the data structures to and from Ruby.
- voidlogic 14y ago"less terrifying than writing Ruby extensions in C" Very true, still terrifying though. I wonder if the reputation of C might not cause a selection bias towards the type of developer that can hack it though. Anyway, this is definitely a solid move.
- jerf 14y agoWhat, specifically, is horrifying, though? It's not C. It's not C++. It's not ASM. You're not going to accidentally implement a buffer overflow, you're not even going to accidentally stomp on Ruby stuff. You might find the Rust language itself intimidating but I'm not seeing what's scary about the integration itself.
- steveklabnik 14y agoI actually wrote the start of a book (it's about 50 pages) specifically on this topic. This kind of thing was something I had on my plate to try, glad someone has already tackled it!
- deleted 14y ago[deleted]
- Scramblejams 14y agoVery cool. Same for Python, pretty please? :-)
- johnbclements 14y agoIIUC, it's a standard FFI call; you should be able to use such a Rust extension in any language with standard FFI conventions.