Rust Devlog

2022-12-23 16:45
tags:
devlog

Devlogs are files where I periodically come and dump what I've learned about a big topic. These notes are pretty uncategorized and mostly just for my reference.


What

I've decided that I want to dedicate some time to learning Rust (properly) and documenting what I figure out. When I say "properly" I mean that I want to follow some actual educational resources and not just poke the compiler until it works on some project or other. This is what I did when I built Firn; it was an arduous process, and I think I could have benefitted from some more classical resources.

This document is more for me than you, dear reader. I'll mostly be posting notes chronologically as I learn.

Why

I'd like to dive deeper into systems programming. I think I would prefer to do it with a simpler language than Rust but I also don't realllllly want to write C or C++ (yet?).

Let's go!


Timeline

2023-01-06

The last 5 days I've been recording myself ("streaming", I call it), as I putter in rust on Esker. It's been super fun to just talk out loud, like I would with rubber-duck-debugging. I do wish I actually had a pair from time to time, but it's also nice to just run a show, a little bit, and see how far I can get in 1-1.5 hours!

This week I managed to get syntax highlighting working. I really just had to suck it up and read some existing code, which I did in one or two of the videos. I encountered a few things I hadn't yet met along the way.

2022-12-23

Today I've been making some more progress wiring up Esker. I'm delighted how much faster I'm moving this time around. I would say 10% of that is that this isn't my first time around with Rust, and the other 90% is that a lot of what I built with First is pretty reusable. I was able to wire up custom user config and ignoring directories/files for publishing in less than half an hour, whereas writing those for the first time probably took several hours. At times I've been able to copy and paste code and only make slight alterations for it to work.

Today, while looking for details on how to implement syntax highlighting using Syntect I found a blog post where the author details a similar journey of building an SSG with rust. Not only that, they use pulldown-cmark as their parser, and extend it to get it working. So now, I can read their module for syntax highlighting and probably figure it out! (Can you tell I'm excited that I'm learning from just reading source code?).

2022-12-14

I'm making quick progress on Esker. It's quite similar to how Firn was built - the architecture is all pretty much the same:

  • load a glob of files into a Site struct,
  • check if a file has valid frontmatter if so -> create a MarkdownFile struct
  • for each markdown file struct, parse it's frontmatter
  • run the markdown through a parser and munge it's links to your site's url gets used.

  • do any other munging necessary while the parser iterates

I'm currently at the step marked by the > above. Right now I've run into Cow values (strings specifically) and I'm very curious as to why I'm seeing them again (I first encountered them when using the orgize parser.) This is encouraging me to get back to Rust in Action, as I originally intended.

2022-12-10

Oh, I'm back! I have been poking at my ssg for my obsidian vault every couple of days. I basically abandoned readong Rust in Action, but I think I will come back to it in time. The SSG is fun - right now it's reading in markdown files in a directory and checking if it has valid frontmatter. I wrote it all manually instead of looking for a frontmatter parser, which means that I just inline, by hand, check that a file has a title, tags, proper parsing of dates and so on. It's fun!

I've just started looking for the markdown parser I'll use and this library looks promising. The author also seems to be prominent in the rust ecosystem and a talented programmer. I was reading a bit of the docs for pulldown-cmark and realized I have lots more ground to cover with rust, and so I should definitely read the second half of Rust in Action. I was stumbling over the syntax for the iterators for this library a bit.

I will say though that this projects is pretty much the same as Firn is ¯\(ツ)/¯ . So, writing things is going a lot faster than the first time.

Today I came across a reddit thread recommending the Anyhow error library, so that might get investigated soon enough.

2022-11-24

Decided to just jump back into building a project. Going to try and build a new static site generator for my obsidian vault. Here I go again...

But, to be fair to myself, I'm at a bit of a low point as winter rolls in. It's dark at 5pm. I haven't found the energy to make a game... and I still want to learn Rust better. I might as well have something to work on while I work through Rust in Action.

2022-11-23

I finally found some time to get back to Rust in action. I began working on the Mandelbrot example project in chapter 2. One thing that I often forget is that I can skip chapters with technical books. I found myself bored and frustrated typing out the Mandelbrot example code and could feel my interest waiting quickly. One of the tricky things about using books to learn is that you never really know if a chapter is going to cover something that you might actually really want to know even if it's simple at the outset.

Nonetheless, I'm glad to be working through something a bit more technical and specific then just reading The Rust Book ™️. When I wrrn, I mostly skimmed the rust book and poked the compiler until it did what I wanted it to do. This time around I'd like to have a bit more of a formal understanding of certain parts of Rust. The idea of trying to write lifetimes without really understanding them, again, it's not exactly appealing.

2022-11-14

  • Learned about a "unit type" (in rust: ()) which stems from ML language.

2022-11-12

  • Started reading Rust in Action.

References

Footnotes