Rust practice Enums 2

Rust practice Enums 2

Aug. 24, 2026, 5 p.m.

gradient image

My general thoughts:

Well I can confidently say I’ve had some trouble incorporating what I’ve been meaning to incorporate. Things outside of programming have been coming up , things including my physical programming location (apartment is quite cozy I need something more office-y), chores, food schedules, nap-time, etc. I believe I have a good routine figured out now. Now that that’s figured out I can focus on the mental aspect of learning this thing.
Issues from being new to the language have been popping up and they’re bound to become less burdensome as I become more fluent but for now they’re a bit of a p.i.t.a.
The best way I can describe it is ; I’ve been meaning to write a simple practice program to get me accustomed to things like syntax , etc. But what I want vs what I can execute does not quite match up. Enums has been my focus as I thought I had a clue but when I wanted to go write an enum incorporated into a confusing code base I had to step back and try my hand again with some more practice.

What is incorporated:

I wrote an enum (I had trouble thinking of an example that resonated with me). Inside the main function I wrote a short intro it was meant to be more interactive but for now this will have to do. It contains 3 variables referring to a different enum arm/values?? Following is a function with a match case triggering different code blocks. Finally I trigger the function passing the different variables as to display the different code blocks.

What I learned:

This practice started from elsewhere and I wanted to fine tune, log and learn so I included the off topic , topics I learned.

1. Strings can have different sizes and enum values must be the same size.
2. Enums want things as an isize.
3. Returning error types = this is a topic I might have to go deeper into. It stemmed from not knowing the syntax I was looking at it looked something like “ fn main() → eframe::Results<()” (WTF!)
4. Type aliasing = used to refer a type by a different name; I’m not entirely sure why you’d do this.

5. Closures || = functions that can be encapsulated in a variable or passed as a variable to another function. I think they are used as Rust is quite literal that when you are building a program you may need some things to work before other things are fully built but you still haven’t built it as you’re actively in the process of building whatever you’re trying to build at least that’s how I understood It would be useful as.



New Cargo Package as a library(--lib) and NOT initializing a new git repo (--vcs none)
$ cargo new enums_2 --lib --vcs none

New Cargo Package as a binary(--bin) and initializing a new git repo.
$ cargo new enums_2 --bin

Save new main.rs file in src preferably with a simple hello world test code to test.

In terminal:
$ cargo build
$ cargo run

In IDE:
// Enums give you a way of saying a value is one of a possible set of values.
// Unlike Structs that allow for grouping together related objects.
enum Food {
Asian,
Latin,
Mediterranean,
}

fn main() {

println!(" Title : Enums Practice 2 ");

let asian = Food::Asian;
let latin = Food::Latin;
let mediterranean = Food::Mediterranean;

fn food_loc(test: Food){
match test {
Food::Asian => println!("Banh Mi"),
Food::Latin => println!("Tortas"),
Food::Mediterranean => println!("Gyro"),
_ => println!("None"),
}
}

//Calling the function to test what it shows.
food_loc(latin);
food_loc(asian);
food_loc(mediterranean);

}


Next Steps:

I’m going to keep trying to get into the groove of things and practice enums and executing them in differing ways until something clicks. Hopefully I can make the next blogs more focused.

Related Blogs