In chapter two you jump right into a project which is awesome. The goal is to make a guessing game and the docs hold yo hand the entire way.
Running the following will build the initial folder structure and also generate some of the files that we are going to need.
cargo new guessing_game
We are then introduced to the Cargo.toml file. I header that cargo took some inspiration from npm and it shows. I feel pretty at home looking at the file.
I wont be covering the project sep by step. The docs do a great job of that and can be found here -> Chapter 2. However, I will be looking at a few things that I found interesting and looking at the final code.
This is a weird concept but the more I think about it, the more I think that it is interesting. Take the following section of the game:
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("You must guess a number. Please guess again...");
continue;
}
};
At this point I don't really undertand this concept and am almost positive that I am using it incorrectly in the above example. Honestly, at this point, it doesn't seem like this should compile. It seems like it would try to set guess = ???? I am not returning anything. I guess that because I am ending the loop, the value is never assigned to anything. It said this would be explained in greater detail later so I am not going to spend to much time one it.
Just like the last post, the below is the actual rust code running on the Vercel server. All of the logic is written in rust but had to be changed slightly to work as a sever application.