# How to Get a Hint for a Rustlings Exercise: CLI and Watch Mode Guide

> Learn how to get a hint for any Rustlings exercise using the CLI command rustlings hint or watch mode. Master Rust by quickly finding solutions.

- Repository: [The Rust Programming Language/rustlings](https://github.com/rust-lang/rustlings)
- Tags: how-to-guide
- Published: 2026-03-05

---

**Run `rustlings hint [EXERCISE_NAME]` in your terminal or press `h` while in `rustlings watch` mode to display the hint for any Rustlings exercise.**

The `rust-lang/rustlings` repository provides an interactive learning environment for Rust where each exercise includes an embedded hint. Whether you prefer command-line tools or the interactive watch mode, retrieving these hints involves specific invocation patterns defined in the Rustlings source code.

## Using the rustlings hint Command

The **CLI `hint` sub-command** provides the most direct way to view exercise hints when you are not running in watch mode. This command is defined in [`src/main.rs`](https://github.com/rust-lang/rustlings/blob/main/src/main.rs) as part of the `Subcommands` enum.

### Syntax and Usage

You can invoke the hint command with or without specifying an exercise name:

```bash

# Show hint for the next pending exercise

rustlings hint

# Show hint for a specific exercise (e.g., variables2)

rustlings hint variables2

```

When you omit the exercise name, Rustlings automatically selects the next pending exercise in the sequence and displays its associated hint.

### How the CLI Hint Works

According to the source code in [`src/main.rs`](https://github.com/rust-lang/rustlings/blob/main/src/main.rs) (lines 56-89), the `Hint` subcommand processes your request through the following steps:

1. **Exercise Selection**: If you provided a name, the system calls `app_state.set_current_exercise_by_name()` to locate that specific exercise. Otherwise, it uses the current pending exercise.

2. **Hint Retrieval**: The program accesses the `hint` field of the `Exercise` struct, which contains a `&'static str` reference to the hint text.

3. **Output**: Finally, it prints the hint to stdout:

   ```rust
   println!("{}", app_state.current_exercise().hint);
   ```

The hint text itself originates from each exercise's [`info.toml`](https://github.com/rust-lang/rustlings/blob/main/info.toml) file, parsed by `InfoFile::parse()` and loaded into memory when Rustlings initializes.

## Getting Hints in Watch Mode

When you run `rustlings watch`, the tool enters an **interactive UI mode** where you can toggle hints without leaving the exercise context. This functionality is implemented in [`src/watch/state.rs`](https://github.com/rust-lang/rustlings/blob/main/src/watch/state.rs).

### The Watch Mode Interface

To access a hint while watching:

1. Start watch mode:

   ```bash
   rustlings watch
   ```

2. When the interactive UI displays the current exercise, press **`h`**.

The first press of `h` toggles the hint display on. Subsequent presses have no effect until you complete the exercise or reset the state.

### Technical Implementation of Watch Mode Hints

The watch mode hint system relies on a boolean flag and event handling defined in [`src/watch/state.rs`](https://github.com/rust-lang/rustlings/blob/main/src/watch/state.rs) (lines 63-70 and 96-100).

When you press `h`, the input thread generates a `WatchEvent::Input(InputEvent::Hint)`, which triggers `WatchState::show_hint()`:

```rust
pub fn show_hint(&mut self, stdout: &mut StdoutLock) -> io::Result<()> {
    if !self.show_hint {
        self.show_hint = true;
        self.render(stdout)?;
    }
    Ok(())
}

```

During the render phase (`WatchState::render`), the system checks the `show_hint` flag. If true, it displays the hint with cyan-colored "Hint" heading:

```rust
if self.show_hint {
    stdout.queue(SetAttributes(HEADING_ATTRIBUTES))?
          .queue(SetForegroundColor(Color::Cyan))?;
    stdout.write_all(b"Hint")?;
    // ...
    stdout.write_all(self.app_state.current_exercise().hint.as_bytes())?;
}

```

The UI also dynamically hides the `:hint` key label once the hint is visible, only showing `h:hint` when `show_hint` is false.

## Where Hints Are Stored

Every Rustlings exercise stores its metadata, including the hint text, in a **TOML configuration file** located at `exercises/**/info.toml`. For example, the hint for `variables2` resides in [`exercises/variables2/info.toml`](https://github.com/rust-lang/rustlings/blob/main/exercises/variables2/info.toml):

```toml
hint = """
Remember that `let` creates an immutable binding unless you add `mut`.
"""

```

When Rustlings initializes, `InfoFile::parse()` reads these TOML files and populates the `hint` field of each `Exercise` struct defined in [`src/exercise.rs`](https://github.com/rust-lang/rustlings/blob/main/src/exercise.rs). This design allows the Rustlings maintainers to update hints without modifying the core application code.

## Summary

- **Use `rustlings hint [EXERCISE_NAME]`** to display hints directly from the command line when not in watch mode, as implemented in [`src/main.rs`](https://github.com/rust-lang/rustlings/blob/main/src/main.rs).
- **Press `h` in watch mode** to toggle the hint display in the interactive UI, handled by `WatchState::show_hint()` in [`src/watch/state.rs`](https://github.com/rust-lang/rustlings/blob/main/src/watch/state.rs).
- **Hints are stored** in each exercise's [`info.toml`](https://github.com/rust-lang/rustlings/blob/main/info.toml) file and loaded into the `Exercise` struct during initialization.
- **The hint system is idempotent** in watch mode—once displayed, pressing `h` again has no effect until you progress to the next exercise.

## Frequently Asked Questions

### Can I see a hint without running rustlings?

Yes. Since Rustlings stores hints as plain text in `exercises/**/info.toml` files, you can read the hint directly by opening the corresponding [`info.toml`](https://github.com/rust-lang/rustlings/blob/main/info.toml) file for any exercise. For example, `cat exercises/functions/functions1/info.toml` displays the hint for the `functions1` exercise without invoking the Rustlings binary.

### Why doesn't the hint show up when I press h multiple times?

The watch mode hint toggle is designed to be idempotent. According to the implementation in [`src/watch/state.rs`](https://github.com/rust-lang/rustlings/blob/main/src/watch/state.rs), the `show_hint()` method checks `if !self.show_hint` before setting the flag to true and re-rendering. Once the flag is true, subsequent calls return immediately without changing the display. This prevents the UI from flickering or re-printing the hint unnecessarily while you work on the exercise.

### How do I add custom hints to my own Rustlings fork?

To add or modify hints in a custom Rustlings fork, edit the `hint` field in the [`info.toml`](https://github.com/rust-lang/rustlings/blob/main/info.toml) file located within each exercise's directory under `exercises/`. The hint value supports multi-line strings using TOML's triple-quote syntax (`"""`). After modifying the TOML files, rebuild the project if necessary. The `InfoFile::parse()` function in the source code automatically loads your custom hint text into the `Exercise` struct when Rustlings runs.

### What's the difference between rustlings hint and watch mode hints?

The **CLI `rustlings hint` command** is a one-off operation that prints the hint to your terminal and exits, making it ideal for quick reference without entering the interactive environment. It is implemented in [`src/main.rs`](https://github.com/rust-lang/rustlings/blob/main/src/main.rs) and directly accesses the `Exercise.hint` field. In contrast, **watch mode hints** are part of the persistent interactive UI (`rustlings watch`) implemented in [`src/watch/state.rs`](https://github.com/rust-lang/rustlings/blob/main/src/watch/state.rs). They toggle within the live interface, display with cyan-colored formatting, and automatically hide the `:hint` key label once shown. Watch mode hints are designed for iterative learning while you edit code, whereas the CLI command suits checking hints before you begin coding.