18 Rust on your computer

 

This chapter covers

  • Cargo, Rust’s package manager
  • cargo doc, Rust’s documentation tool
  • Working with user input
  • Using files

We have seen that it is possible to learn almost anything in Rust just using the Playground. But if you have read this far in the book, you probably already have Rust installed on your computer. And there are always things that you can’t do with the Playground, such as working with files or writing code in more than just one file. Some other things that are best done on your computer for are user input and command-line arguments. But most important is that with Rust on your computer, you can use external crates. We have already learned a few crates, but the Playground only has access to the most popular ones. With Rust on your computer, you can use any external crate at all. The tool that binds this all together is called Cargo, Rust’s package manager.

18.1 Cargo

One of the largest selling points of Rust is that pretty much everyone uses Cargo to build and manage their projects. Using Cargo gives Rust projects a common structure that makes it easy to work with external code written by multiple people at the same time. To understand why Cargo is found almost everywhere in Rust code, let’s first see what writing Rust is like without it.

18.1.1 Why everyone uses Cargo

18.1.2 Using Cargo and what Rust does while it compiles

18.2 Working with user input

18.2.1 User input through stdin

18.2.2 Accessing command-line arguments

18.2.3 Accessing environment variables

18.3 Using files

18.3.1 Creating files

18.3.2 Opening existing files

18.3.3 Using OpenOptions to work with files