0:00
/
0:00
Transcript

Model-View-Controller in Rust

Way more difficult than I thought!

I’ve been working on a software tracker synth in Rust, inspired by this.

One major problem I’ve faced was, MVC in Rust just doesn’t work like I thought.

It appears you can’t really just have a model and some views, and then have a controller class that creates these and passes parts of the model to the views.

In this video I’ll show you the kinds of problems I ran into. Basically they come down to problems with borrowing; you can’t have two mutable references to the same thing at the same time, so your controller just freely pass around mutable links to views.

Passing different parts of a model to different views would require multiple mutable links to different parts of the same data structure, and I couldn’t find a way to get this to work.

However, it can be done, and the trick is to use RefCell (for interior mutability) and Rc (for multiple ownership).

Full code is here: https://github.com/caveofprogramming/rust/

I’ll probably also make videos on the software synth I’m working on, as soon as it can play an actual melody.

Discussion about this video

User's avatar