Confusion around `Ok(num)` pattern in guessing game example (Rust Book)
โ Rust ๐ 2026-04-25 ๐ค surdeus ๐๏ธ 1I'm new to rust and learning the language via the The Rust Programming Language book ( stable version ) and following the Programming a Guessing Game chapter and I got confused in this part:
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
here when I type Ok(num) my IDE zed gives suggestions to import some external items/traits related to num, which confused me on the first time as I thought that the code example in the book is missing an import, but when I tinker with the name num then I realise that it is just a placeholder name, and we can use any name instead of num.
This might be quite confusing for someone who is new to the language and learning for the first time, It wasnโt immediately obvious that num is not something predefined or requiring an import.
Maybe we can explicitly mention it in the docs, that name like num in Ok(num) is just a placeholder name and you can use any name instead of num, so that new people like me does not confuse with the IDE suggestions.
Instead of opening the issue directory to the docs repo for this, I think to discuss it here and get some suggestions of other community members or if others had similar confusion and if thereโs a better way to interpret this as a beginner.
3 posts - 3 participants
๐ท๏ธ Rust_feed
