Context

I have had a long and unfortuantely anti-climactic journey with Rust so far, which I am fully responsible for. Over the last 2 years, I have had about five separate two-week long periods of time where I decided that I was finally going to write the most idiomatic Rust code the world has ever seen, and finally become a true Rustacean. In this time, I have worked with many people who are skeptical of Rust, which I think is very fair given that I have primarily worked in the Embedded Systems industry, where C/C++ has dominated for eons. I have rarely had good means to argue this skepticism with my optimism for the language, since I have never taken the real time to learn it in depth.

Currently, I understand the fundamentals of the language fairly well, but I have yet to use it for a project where I could imagine that another language would have suffered from memory bugs or optimization issues. Creating this Static Site Generator (SSG) won’t necessarily do that, since it is a small project, but I intend on it enabling me to do so in the near future.

With this in mind, I want to write down everything I learn about Rust through designing this project as well as simply fighting the compiler about things that are common knowledge to the true Rustacean.

Also a big shoutout to Shane Snover and his blog for reigniting some motivation in me to finish this project and to share blog posts in hopes of helping myself and others!

Project Goals

The goal of this project is to provide myself with a simple means to write and post to my blog, as well as edit my website’s home page. I already use Obsidian for pretty much all kinds of other writing and I love it, so I wanted to make it easy for me to basically create my website with Obsidian.

My SSG is essentially just a translater between my Obsidian (Markdown) + .toml file and HTML + CSS.

ssg-block-diagram

Rust Learnings

Path vs PathBuf

When I first saw these two types flying around in coding examples, I was very confused. In hindsight, it’s super simple.

Path: Borrowed slice, No new allocation, immutable

Use it when you want to…

PathBuf: Owned Struct, Allocates memory on heap, mutable

Use it when you want to…

One is just a path that you can look at, the other is a path buffer lol.

Lifetimes

When Rust skeptics say that the language’s syntax is complicated or confusing, this is what they mean. Now I am no compiler engineer or programming language designer (although this is a dream project of mine), but the syntax for lifetimes does not feel intuitive at all. It seems to me that this person agrees.

Here is my attempt to summarize lifetimes:

Lifetimes are labels that tell the compiler how long a borrow remains valid, so that it never points to data that has been deleted. NO DANGLING POINTERS

Traits, implementations, from

OnceLock