Reactive programming in Rust

The more I use Kotlin and RxJava in my professional space, the more my Android apps just become reactive streams that transform stuff until it eventually becomes a stream of view states. The more I take that approach the more I like how it works out. So that has gotten me thinking about if I could start taking that approach in my Rust programs as well.

Tokio seems to be the big thing for Async in Rust but it also seems to be targeted at networking only. So what is the reactive story in Rust? Is there anything around in Rust that would be akin to the ease of use and functionality of RxJava or even any demand for it? And yes I know RxRust exists but it also hasn't seen a commit for a couple years so I am thinking it is not as well developed as I am looking for.

4 Likes

I have built carboxyl a while ago. It is usable, but I am also not actively developing it further. You may be interested in this discussion that happened a few days ago. Basically, would I build it again today, it would probably be based on asynchronous futures and streams, I just do not have a use case at the moment to motivate me to do that. Still, unless your performance requirements are very tight, carboxyl can serve your need for a functional reactive stream library.

2 Likes

Thanks. I'll definitely checkout your library.

You can use tokio purely without its networking stuff. That's what I was doing just yesterday actually to play around with it.

I created some futures that simply returned some numbers, had them joined, and added them together to produce another future.

For streams, I did the same. Create two streams that repeately generate the numbers 9 and 2 (could've been random numbers, but it was faster just to do this to play), call .select on them and then poll to grab a number. Then you run them with tokio's core/stream runner.

I think tokio is your best option here. It's pretty simple once you understand it.

1 Like

Thanks for the suggestion! I'll have to give that a try. Last time I looked into Tokio it didn't seem that simple to get started with, but that was quite some time ago.

I think I'm going to write a little article on using futures and streams in the most simplest of ways to show people they have nothing to fear :slight_smile:

Rust's UI story is still developing though. I think the GTK+ bindings someone did (Relm?) is the best we have so far.

3 Likes

Yeah I was toying with the idea of making a simple game with SDL just so my Rust skills don't get too...rusty... but I figured I'd propose this question first and think about displaying after I figure out what I want to build.

You should check out ggez for anything to do with 2D games.

1 Like

We had a few discussions in tokio. And, despite ongoing changes in it, the gist is that Tokio is only for I/O. tokio isn't following rx, and isn't planing to do so.
This is a big deal, as the main observable's contract is not upheld in tokio.

We created a group on github as a place for experimentation, discussions and code that will implement rx and Reactive Streams.

Join us. As tokio member said

If you want to see rx concepts happen, the quickest strategy is to implement it yourself.

4 Likes

Maybe GitHub - rxRust/rxRust: Rust implementation of Reactive Extensions.