Rust language

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. 

It currently has bindings with Port Audio. 

 

 

4 Likes

Rust has just reached version 1.0 ! 

http://blog.rust-lang.org/2015/05/15/Rust-1.0.html

Can't see many examples of using it for audio apps but it looks promising... 

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.

1 Like

Looks like that project is moving along nicely:

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.

Curious to hear what others think about it.

1 Like

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!

3 Likes

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.

1 Like

Implementing data structures is like the worst way to learn that language.

There’s a rust-audio discourse out there if anyone is interested

2 Likes

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++.

1 Like

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?

1 Like

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.

3 Likes

Thank you for your awesome answer!

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.

1 Like

I spent about three weeks trying out Rust. It was fun. But there’s no decent GUI so it’s not useful to me.

For plugin development, unless the Rust part is a self-contained static library which will be used in other projects, I’d stick to C++ for now :slight_smile:

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.

See GitHub - RustAudio/vst-rs: VST 2.4 API implementation in rust. Create plugins or hosts. Previously rust-vst on the RustDSP group.

Personally I’d really would had liked to give GitHub - emilk/egui: egui: an easy-to-use immediate mode GUI in pure Rust a try if I was using Rust.

2 Likes