vault backup: 2025-03-24 09:38:53
This commit is contained in:
parent
e2b46fb082
commit
56f54bdeef
@ -4,3 +4,24 @@ a random number, and compares the two to say whether the guess is correct,
|
|||||||
lower, or higher. It introduces us to key concepts in Rust such as module
|
lower, or higher. It introduces us to key concepts in Rust such as module
|
||||||
importing, the idea of mutability, how to define variables, and other
|
importing, the idea of mutability, how to define variables, and other
|
||||||
interesting type things.
|
interesting type things.
|
||||||
|
|
||||||
|
## Breaking Down some things
|
||||||
|
### Types, and variants
|
||||||
|
When creating the variable `guess` we created it as
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let mut guess = String::new();
|
||||||
|
```
|
||||||
|
|
||||||
|
where we call `String::new()`. `String` is a type, that has a function `new`
|
||||||
|
integrated into that type.
|
||||||
|
|
||||||
|
Then, we read in the data. Some interesting things happen here:
|
||||||
|
1. We use `&mut guess` where `&` signifies a *reference* to an object
|
||||||
|
2. We have an `.expect()`
|
||||||
|
a. `.read_line` returns a string, but it also returns a result
|
||||||
|
b. This result is an *enumeration* type, with each possible
|
||||||
|
result being a *variant*.
|
||||||
|
|
||||||
|
Wacky stuff.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user