Been reading about the Rust programming language. Looks very interesting and promising. I wonder if it could be linked into Juce somehow - or perhaps another cross-platform audio framework will come out of it.
I'm obviously a little late to this thread, but the Servo team at Mozilla is discussing implementing the Web Audio API (https://github.com/servo/servo/issues/6710), which seems like a good project to follow if you're interested in Rust and its audio applications. It's still extremely early stage, but I've got my eye on it.
I’ve been using Rust, alongside C++, for over a year now. I find it very difficult to learn, but what it offers is amazing. I’ve built quite a few tools I’ve needed with Rust.
I’ve convinced a client to use it for an upcoming project for a signal processing backend and CLI tool. It’ll be my first proper foray into Rust. I’ll report back once I’ve got my feet wet!
It’s a great language, but the learning curve is pretty ridiculous. I just finished implementing a prefix tree with it. I also built a serial number generator with it. I haven’t had the chance to do anything audio-related yet, but I think I’ll attempt it soon.
Would you be willing to elaborate on why you think data structures are the worst projects to use to learn Rust?
I’ve written maybe 8-10 toy projects using Rust and so far, the prefix tree has been the thing that has taught me the most, so I think it actually was the most informative projective I’ve done with it. I ended up using pointers, RefCell, Options, Results, Vec, etc; it’s been challenging, but great.
I like this booklet a lot on linked lists in Rust. It brings up a lot of the hazards in handrolling data data structures.
I think trees are pretty straightforward in Rust via enum variants, but the moment you start throwing unsafe code around you can get careless just like in C/C++. Sticking to idiomatic, safe Rust really helps you appreciate the borrow checker and understand it.
I think building something like an echo/chat server is a much better introduction to the language.
I actually used that book for reference a few times. I did mention it was a “toy project” because I wouldn’t ever use my own encryption or data structures in a serious project.
I didn’t need to use unsafe Rust at all. To me, using unsafe Rust, unless you absolutely can’t avoid it, sort of defeats the purpose of even using it. If I think I I’d ever need to use unsafe Rust, I’d just use C++.
Also, the chat project you mentioned sounds great, but that really is beyond me. I probably couldn’t build a chat server even in a language I’m most fluent in, like C++, otherwise I would.
I guess by now your feet are either soaked or stone-dry :). How has your experience been with Rust? I’m looking into using it for a couple of low-level dsp libraries right now but am not sure everything is mature enough even now.
The first couple of problems I encountered are a very promising platform-agnostic simd support with std::simd that unfortunately doesn’t seem complete and problems with generics + traits where some functions seem to be missing from some traits (copysign for instants) and I really have a hard time accepting that I can only build stuff using crate with an active online connection. Are you still using Rust for professional audio development?
TLDR; No, no longer using Rust, and we didn’t use it for audio, but we did use if it for signal processing, data streaming and networking.
We successfully used Rust to build a library for handling data streaming and networking for an IMU device. We used JUCE for the front-end GUI. We spent quite a lot of time working on the FFI layer, converting raw C types into Rust and vice versa. Rust also forced us, multiple times, to re-evaluate our design, which was often frustrating, but ultimately led to a good design, following Rust idioms such as cross-thread communication via Channels. In retrospect, we probably could have completed that part in about 1/4 of the time in C++, but I think the design would not have been as tight, and we would have been more likely to hit runtime bugs.
Once you get used to the borrow checker (and the lack of OO), Rust is a very nice language to work with. It’s definitely made me a better C++ programmer - the things which are now commonplace in C++ such as const and move are default in Rust, and the compiler will catch a lot of common memory-related mistakes, as well as prevent you from doing things which you think will be fine!
If your DSP library is designed to be self-contained, and to be used from multiple languages (like our API is) then Rust might make sense. But just be aware that, like C++, it requires some time investment to learn.
That’s what I’m going for for now as well :). I started using const a lot more in C++… and my biggest wish would be some kind of [safe] sections in C++ where dangerous stuff was prohibited… sort of the opposite of Rusts [unsafe] concept. Design-wise I so far see a similar effect to when I was writing some stuff with “functional” C++ - only structs and pure methods allowed.
So maybe I just adapt my C++ to be more rust-like and look at this as an exercise. Writing inter-op code, potential troubles with debugging a mixed language plugin and not being able to work offline make me doubt I can get more done in the same amount of time.
There are some Rust GUI frameworks around, but for plugin development, I’ve not seen much more than VST2 plugins without an editor, and VST3 seems incompatible with Rust, I think due to the COM architecture.