Rustlings Session 2: Structs, Enums, and Why I'm an Idiot (Sections 7-9)

Six hours after finishing Session 1 , I was back at it with Rustlings. This time tackling sections 7-9: structs, enums, and strings. What should have been a smooth continuation turned into me fighting with basic enum syntax for far longer than any reasonable person should.

The Plan vs Reality

The plan was simple: bang out sections 7-9, maybe grab a tea, feel good about my Rust progress. Reality had other ideas.

Sections 7 and 9 (structs and strings) went fine. Nothing particularly challenging there—just getting familiar with Rust's way of doing things I already understood conceptually. Structs are structs, strings have their &str vs String quirks, all fairly logical.

Then I hit section 8. Enums.

The Enum Disaster

Here's the thing about enums in Rust: they're brilliant. They're like a hybrid between traditional enums and algebraic data types from functional languages. You can have variants that carry data, variants that don't, variants with named fields—it's powerful stuff.

I just completely fucked up the syntax.

Looking back at my code comments, I can see exactly where I went wrong:

// That was a pain in the arse because I was being stupid and put the main fn inside the enum block.
// I am an idiot. It took me a while to figure out why the compiler was complaining about the main function not being found.

Yes, I somehow managed to nest my main function inside an enum definition. The Rust compiler was understandably confused, I was getting increasingly frustrated, and what should have been a 20-minute exercise stretched into something much longer.

The particularly annoying bit is that once I sorted out where functions actually belong (hint: not inside enum blocks), the exercises were straightforward. Pattern matching with match expressions, handling different enum variants—it all clicked into place.

What Actually Worked

Despite my enum-induced brain fog, there were some genuinely satisfying moments:

Structs felt natural. Coming from other languages, the concept isn't foreign, but Rust's approach to ownership and borrowing adds some interesting wrinkles. The exercises walked through classic C-style structs, tuple structs, and unit structs in a logical progression. It also reminded me of TypeScript.

String handling made sense. The &str vs String distinction is one of those Rust concepts that trips up newcomers, but the exercises did a good job of showing when to use which. Plus, methods like .trim(), .replace(), and format macros work pretty much as you'd expect.

Pattern matching is genuinely nice. Once I stopped being an idiot with the syntax, match expressions felt quite elegant. There's something satisfying about exhaustively handling all possible cases.

The Learning Curve

What's becoming clear is that Rust has opinions about how you should structure your code, and fighting those opinions is pointless. The compiler is incredibly helpful—it'll tell you exactly what's wrong and often suggest how to fix it. But you need to actually read the error messages instead of just staring at your screen wondering why things aren't working.

The ownership system is still lurking in the background, not causing major issues yet but making its presence known. I suspect that's going to be the real challenge when I hit more complex exercises.

Session Stats

Time taken: About 1 hour 15 minutes (would've been much quicker without my enum catastrophe)

Sections completed: 7-9 (structs, enums, strings)

Compiler errors due to stupidity: Too many to count

Satisfaction level: High, once I sorted myself out

What's Next

I'm quite enjoying this learning process, even when I'm being a complete numpty. The exercises are well-structured, the compiler feedback is excellent, and there's a real sense of progression.

Next session I'll probably tackle more advanced topics. Hopefully without putting functions where they don't belong.

The nice thing about Rustlings is that it forces you to actually understand concepts rather than just copying syntax. You can't move forward until your code compiles and passes the tests, which means you're genuinely learning rather than just following along.

Right, that's enough rambling about my battles with basic syntax. Time to go do something that doesn't involve confusing myself with enum definitions. Probably read more Wereworld or... something. It's midnight.

P.S. - If you're starting Rustlings yourself, just remember: functions go outside enum blocks. You'd think that would be obvious, but apparently not for everyone.