CLOSE

Archive:

2021
Subscribe:Atom Feed

"First Steps With Rust..."

Posted: 23 July, 2021

My other half's become a bit of a twitcher over the last year or so, which has been a good excuse to get out, travel, and see some countryside. It's not exactly my bag, but given I've completed most of the Pokemon series I'd be lying if I said I didn't get the appeal. And, as any good trainer knows, you're going to need a Pok├ędex, so I offered to make one, online, so she could record her sightings.

Birdydex

Functionally, I thought I'd start out relatively simply and record the following:

  1. Bird name
  2. Date/time
  3. Rarity
  4. Gender
  5. Weather condition
  6. Notes
  7. Geolocation

For the name I want to have some sort of fuzzy search, to save her from ever having to type the full name, and to allow me to key off it in the back-end. Ideally, I'd like Geolocation to use the GPS on her phone, and/or a navigable map, so she can drop a pin, when she's out, to mark the spot.

Rust

Rust has been bubbling up my "should look at this" pipe for a long time. There's been a lot of talk in gamedev circles about using it to develop tools, and in some cases, engines, and I know several 'sceners are using it for their frameworks. I really should kick the tyres...

My personal interest in Rust centres around using it as a "proper" development language for the browser, via Web Assembly. For games, mostly, but given I still pick-up contract work occasionally, it'd be nice to use it for general web-apps, as well.

Rust and Rocket

Birdydex is a slightly different usecase to any of that, though. Despite my natural desire to make an all-singing, all-animating, full 3D "app" (game) out of it, I'm going to resist. At least for now. Just a simple page, and backend. I can build reports, over time, until the cows come home.

So I started looking at the various libraries/frameworks that are available, and a lot didn't suit my needs, or just looked a little immature. But Rocket jumped out.

To quote their spiel, "Rocket is a web framework for Rust that makes it simple to write fast, secure web applications without sacrificing flexibility, usability, or type safety". Flicking through the docs and examples, it looked exactly like the sort of thing I'm after.

What appeals even more, is the client traffic is routed directly to my Rust application, via Nginx. No need for a heavy Apache install. No need for a big Postgres/MySQL backend. Just something light weight, and nippy.

On my last web job I used Handlebars for page templating, and SASS for CSS compilation. Rocket uses Handlebars out of the box, and has an additional fairing for SASS, so going in, I had the warm-fuzzies that I was going to agree with the Rocket developers quite a lot.

CLion

JetBrains IDEs have been around for about as long as I have, and for their entire 20 year existence I've laughed at their fat, bloated, java-based asses. I've tried them many times over those years (sometimes forced), and their slow start-up times, incredibly high RAM usage, and propesity to crash have always put me off.

But guess what? Technology has finally caught up with them! It doesn't matter if my text editor is using 4gig of RAM, my browser is using twice as much! Start-up times improve dramatically with NVMe drives, so that's not a problem, and hey, everything crashes!

Oh...

Visual Studio is slow, resource hungry, crashy, prone to random hangs, and it takes an age to start-up. It is, quite honestly, one of the worst pieces of software that I've ever used, but it's got an amazing debugger, and with Visual Assist installed, it's kinda bearable. At least, it is on the days it's not crashing.

I had a brief flirtation with JetBrains Rider while teaching a Unity course, but consigned it to the bin of JetBrains in my head and forgot about it. Then I got invited onto the Rider for UE4 Alpha...

Rider for Unreal Engine is a delight. It's moved quickly to integrate deeply into Unreal and its funky macro-based C++. The Debugger has become extremely competent. I use it daily, and while it's resource hungry and takes an age to start-up, it is at least stable. It doesn't hang. It starts compiling the instant I CTRL-B. I missed Visual Assist at first, but I've thrown myself into Resharper for C++ and it does pretty much everything I need. It's home, for most of my days, so I was secretly hoping that Rider would have a Rust extension, but apparently, that's been reserved for CLion.

Clion isn't Rider. Except when it is. The lines are blurry with JetBrains stuff, but there's enough that's similar to make transitioning to it quick. There is the odd wrinkle when jumping between the two, but a dive in to the settings can make them similar enough.

The Rust integration is great. Good static analysis. Nice build features. Easy to navigate to fix errors. Can even hook into WSL remotely. It ticks every box. And, being JetBrains, it's a couple of plugins away from being a monster IDE that handles Moustache, CSS, Javascript, HTML and XML, all in one box. It's quite the thing.

Over the last 12 months I've gone from laughing at JetBrains IDEs to paying for the full suite. I am a complete convert. Even I'm surprsied by that. I'd love a specialised Rust IDE from them, or at least, Rider for Rust, but to be honest the differences between the IDEs seems to narrow every version, so whatever...

Development

The problem with Rust is the syntatic sugar. Rather than move away from the complicated semantics that have driven C++ into the ground, they've gone whole-hog and created some very unreadable syntax of their own. Because of this, Rust is not an easy language to pick-up and grok, and the brevity in a lot of the documentation makes it non-trivial to "learn-by-doing". To be honest, I've not enjoyed it one bit.

Rust's setup and package management, on first use, appears to be well thought out and simple to use. The compiler's error reporting is probably some of the most useful I've ever seen. It's easy to get going, and it's easy to pull-in code, but that ease gives me pause...

In the end, the Rust part of my application ended up being a couple of hundred lines of well spaced code (written by me), and I-have-absolutely-no-idea how many thousand lines of code from the packages that were imported. There's so much that's hidden from me that I'm a little bothered by it... Yes, I can kinda dig down in the IDE and get to it -- and it is, of course, all open source and on GitHub if I can be boether to search for it -- but that's not how it tries to present itself.

Rust really likes its black boxes and, well, from bitter experience, I don't...

Hilariously, my "project to learn Rust" ended up with me writing as much Javascript as I did Rust. But, and this isn't to be sniffed at, the entire thing is "not very much code". It is blazingly fast and it uses no resources at all. For the most part I'm serving what amounts to a static site, even if it's made up from a lot of templated parts to avoid repetition. Javascript took care of the fuzzy search on name and I used a 3rd party mapping service, along with a smidge of client-side code, to handle the geolocation. Rocket sets up the routes and I do a little bit of validation and parsing, and talk to the DB.

During dev, the compile/refresh/iterate times were miniscule, meaning I could bounce between the browser and the IDE, make changes, and test things quickly.

This has been one of the better web dev experiences that I've had.

Musings...

Obviously I'm not quite finished with the project. I need to finish the database integration and deploy the app to one of my servers. After that, it's a case of data-mining, making reports, and on-going maintenance.

It's unfair to make much of an assessment at this stage, but I wouldn't be here if I didn't have some thoughts:

I'm going to need to find something else to do to give Rust a proper chance...