Time and the outside world

A program that only computes is a test; this chapter makes it talk to the machine it runs on. These eight lessons measure time with Instant and read the wall clock with SystemTime, compute dates from a Unix timestamp, and seed a random generator of their own. A regular expression splits a log line, the arguments arrive from env::args with a usage message and an exit code, and a configuration is read from the environment. The chapter ends with the sockets of the standard library, a TCP client and a tiny server, and with the child process whose exit status is passed on.

103 Instant, SystemTime and Duration measured time against wall-clock time, Duration arithmetic and a timing that measures real work (C++ 072) Open 104 Dates and formatting a Unix timestamp, the date parts computed by hand, and the chrono crate named for the rest (C++ 073) Open 105 Random numbers a seeded generator written by hand, a distribution over a range, and the rand crate (C++ 074) Open 106 Regular expressions with regex the regex crate, captures, a log line split apart and a pattern that does not match (C++ 071) Open 107 Arguments and exit codes env::args, a small option parser, a usage message and a non-zero exit code (C++ 076) Open 108 Environment variables and config env::var, a default, a config file read at start-up and a missing value reported (C++ 076) Open 109 TCP clients and servers TcpListener, TcpStream, a request line read from a socket and a tiny HTTP answer (no C++ counterpart) Open 110 Running other programs Command, output and status, a child process and the exit code passed on (no C++ counterpart) Open

Lessons