Loading tutorials
read_line, the method that does the actual reading from standard input. It assumes you can write basic Rust (variables, functions, match), that you know String is an owned, growable text buffer and &mut is a mutable reference, and that you have a handle from io::stdin()6 min readread_line returns a Result instead of a bare value. This chapter explains what that Result holds and the three ways to deal with it: match, expect, and the ? operator. It also covers how to choose between them.6 min readString versus &str, mutable references, and match on a Result. You should also know how to run a program with cargo run. The previous chapters showed how to call read_line and handle its io::Result. This chapter covers what is in the buffer afterward and 6 min readString with read_line, handle its io::Result, and trim the trailing newline. It also assumes you know match, Result, and the difference between String and &str. Here you turn the text into typed values and handle the ways that con4 min readprint! can fail to appear before your program waits for input. It then shows how to fix that with flush. It assumes you can already read a line with read_line and handle its io::Result, as covered in the earlier chapters. It also assumes you kn6 min readread_line, handle its io::Result with ? or expect, and trim and parse the text. If a loop that re-prompts on bad input is new to you, a quick look at that earlier chapter will help. Here you will learn how a program learns that no more input will6 min readread_line, trim its result, and call parse on the text. You should also be comfortable with match, loop, and the ? operator in a function that returns io::Result. Here you combine those pieces into a loop that keeps asking until the user gives a 6 min readread_line, handle its io::Result with ?, and parse text with parse. It also assumes you know what String and &str are and how to run a program with cargo run. Here you move from "one line" to "all the lines until the input ends".5 min readString, trimmed it, and parsed it as one value. Many programs receive several values on one line, such as 3 4 5 or add 10 20. This chapter covers how to split such a line into tokens and turn those tokens into typed values.6 min readread_to_string, which collects everything on standard input into one String. It assumes you can already use read_line, handle an io::Result with ?, and parse text with str::parse. It also assumes you know what BufRead and lines() do.6 min readResult, the ? operator, and how to read lines from a locked stdin handle. You should also be comfortable with traits at the level of "a type can implement a trait". Everything here builds on the input functions from the earlier chapters.5 min readread_line, lines(), parse, and Result. It also assumes you can write a main that returns io::Result or Result<(), Box<dyn Error>>. The goal is to structure input code so a unit test can run it without a terminal.5 min read