# Let's dig in!

{% code title="main.rs" %}

```rust
use std::io;

fn main() {
    println!("Guess the number!");

    println!("Please input your guess.");

    let mut guess = String::new();

    io::stdin().read_line(&mut guess)
        .expect("Failed to read line");

    println!("You guessed: {}", guess);

}
```

{% endcode %}

The first line `use std::io` brings the standard io (input/output) library into scope. We've covered `main` and `println!`, so let's go into `let`, `mut`, and `String::new`. `let` is used to defined variables, like so:

```rust
let foo = bar;
```

A standard variable is immutable (cannot be changed), but `mut` makes it mutable.

```rust
let foo = bar; // immutable
let mut foo2 = bar; // mutable
```

Here's the error message you will see if you try to change an immutable variable.

![](https://2720625490-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LBlB5eCVilPmyCc9hb0%2F-LBlSURMVV3zkjDhOHC0%2F-LBlYfITXr176dVSMH-X%2FScreen%20Shot%202018-05-05%20at%202.26.21%20PM.png?alt=media\&token=17b400cb-9fa9-40ae-ad56-2fa0787ed05b)

Rust also binds variables to a certain type when they are initialized. For example, with line :

{% code title="" %}

```rust
let mut guess = String::new();
```

{% endcode %}

`guess` is bound to an empty string. Here's an example of how this works:

![](https://2720625490-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LBlB5eCVilPmyCc9hb0%2F-LBlSURMVV3zkjDhOHC0%2F-LBlhaDycJoU3dT3dEL_%2FScreen%20Shot%202018-05-05%20at%203.09.56%20PM.png?alt=media\&token=dd76e890-dfcb-471e-9a02-eb2c41d77d06)

The next part of the code, `.read_line(&mut guess)`, calls the [`read_line`](https://doc.rust-lang.org/std/io/struct.Stdin.html#method.read_line) method on the standard input handle to get input from the user. We’re also passing one argument to `read_line`: `&mut guess`. `read_line` requires a string as a parameter and that string must be mutable. The `&` indicates that it is a reference. References are immutable by default, so the `&mut guess` is required.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jmkoni.gitbook.io/rust/guessing-game/lets-dig-in.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
