官术网_书友最值得收藏!

  • Rust Standard Library Cookbook
  • Jan Nils Ferner Daniel Durante
  • 542字
  • 2021-08-27 19:44:58

To get the most out of this book

This book has been written with and tested for the Rust versions rustc 1.24.1 and rustc 1.26.0-nightly; however, Rust's strong backward compatibility should make it possible for you to use any newer versions for all chapters except the last. Chapter 10, Using Experimental Nightly Features, is working with cutting-edge technology that is expected to improve through ground-breaking changes.

To download the newest Rust version, visit https://rustup.rs/, where you will be able to download a Rust installer for your operating system. It's okay to leave it at the standard settings. Make sure to call rustup default nightly before starting Chapter 10, Using Experimental Nightly Features. Don't worry, you'll be reminded again when it's time.

An active internet connection is required for many recipes, as we will work intensively with crates. These are Rust's way of distributing libraries over the internet, and they are hosted at https://crates.io/.

You might wonder why a book about Rust's standard library, or std for short, uses so much code from outside the std. That's because Rust, in contrast to most other system languages, was designed with strong dependency management in mind from the beginning. It's so easy to pull crates into your code that a lot of specific functionality has been outsourced to officially recommended crates. This helps the core standard library that is distributed with Rust to stay simple and very stable.

The most official group of crates after the std is the nursery (https://github.com/rust-lang-nursery?language=rust). These crates are the standard for many operations and are nearly stable or generic enough to be in the std.

If we can't find a crate for a recipe in the nursery, we look at the crates of the Rust core team members (https://github.com/orgs/rust-lang/people), who put a lot of effort into providing functionality that is missing from the standard library. These crates are not in the nursery because they are usually specific enough that it is not worth allocating too many resources to actively maintaining them.

All the code in this book has been formatted with the newest rustfmt (rustfmt-nightly v0.4.0), which you can optionally download using rustup component add rustfmt-preview and run with cargo fmt. The code on GitHub (https://github.com/jnferner/rust-standard-library-cookbook) is going to be actively maintained and consequently formatted using a newer version of rustfmt, if available. In some cases, this means that the source code line markings can become outdated. It should not be hard to find the code, however, as this shift is usually no greater than two or three lines.

All code has also been checked by Rust's official linter, clippy (https://github.com/rust-lang-nursery/rust-clippy), using version 0.0.187. If you want, you can install it with cargo +nightly install clippy and run it with cargo +nightly clippy. The newest version tends to break quite often though, so don't be surprised if it doesn't work outright.

Some clippy and rustc warnings have been left in the code intentionally. Most of these are either dead code, which happens when we assign a value to a variable to illustrate a concept and then don't need to use the variable anymore, or usage of placeholder names such as foo, bar, or baz, which are used when the exact purpose of a variable is irrelevant to the recipe.

主站蜘蛛池模板: 蓬莱市| 安多县| 夹江县| 扶风县| 沁水县| 湟中县| 南华县| 盘锦市| 翁源县| 乌拉特中旗| 潜山县| 恭城| 延川县| 古交市| 尚义县| 铜山县| 黑水县| 八宿县| 栾城县| 新余市| 千阳县| 宜兴市| 寿光市| 婺源县| 海林市| 赣榆县| 临海市| 马龙县| 茂名市| 新化县| 博乐市| 靖宇县| 宁河县| 平和县| 霍山县| 观塘区| 乌海市| 建水县| 基隆市| 临澧县| 洛扎县|