Search⌘ K
AI Features

Moving Input to a Function

Explore how to encapsulate repeated user input handling in Rust by moving it into functions. Understand the benefits of abstraction and the DRY principle, helping you write cleaner, more readable game code.

A function and its advantage

Whenever we have commonly used code, it’s a good idea to move it into a function.

This has two advantages:

  1. We don’t keep typing the same code
  2. A single call to what_is_your_name() is less disruptive of the overall flow of our function, which lets us concentrate on the important parts. This is a
...