Book Image

Rust Standard Library Cookbook

By : Jan Hohenheim, Daniel Durante
Book Image

Rust Standard Library Cookbook

By: Jan Hohenheim, Daniel Durante

Overview of this book

Mozilla’s Rust is gaining much attention with amazing features and a powerful library. This book will take you through varied recipes to teach you how to leverage the Standard library to implement efficient solutions. The book begins with a brief look at the basic modules of the Standard library and collections. From here, the recipes will cover packages that support file/directory handling and interaction through parsing. You will learn about packages related to advanced data structures, error handling, and networking. You will also learn to work with futures and experimental nightly features. The book also covers the most relevant external crates in Rust. By the end of the book, you will be proficient at using the Rust Standard library.
Table of Contents (12 chapters)

Getting started

You probably already know what a CSV is, but a little refresher won't hurt.

The idea of the format is to take a table of values and write all rows down as records. Inside a record, every column item is written down and separated by a comma. That's where the format's name comes from—comma-separated values.

Let's do an example. In the following code, we are going to write a CSV comparing various planets in the solar system to our own. A radius, distance from the sun, and gravity of 1 means exactly as on earth. Written as a table, our values look like this:

name radius distance_from_sun gravity
Mercury 0.38 0.47 0.38
Venus 0.95 0.73 0.9
Earth 1 1 1
Mars 0.53 1.67 0.38
Jupiter 11.21 5.46 2.53
Saturn 9.45 10.12 1.07
Uranus 4.01 20.11 0.89
Neptune 3.88 30.33 1.14


Take every row, separate the values by commas, put them each on a separate line, and you end up with the CSV file: