|
| 1 | +# Code Examples for _Programming Rust_ |
| 2 | + |
| 3 | +This repository contains complete code for the larger example programs |
| 4 | +from the book “Programming Rust”, by Jim Blandy and Jason Orendorff. |
| 5 | + |
| 6 | +Each subdirectory is a distinct Rust project, with its own Cargo.toml file. You |
| 7 | +should be able to enter each directory and use `cargo build` and `cargo test`. |
| 8 | +For those projects that define programs, `cargo run` should run them. |
| 9 | + |
| 10 | +The example code in this directory and its subdirectories is licensed under the |
| 11 | +terms of the MIT license. See [LICENSE-MIT](LICENSE-MIT) for details. |
| 12 | + |
| 13 | +## Chapter 2: A Tour of Rust |
| 14 | + |
| 15 | +- The `gcd` directory holds the command-line program for computing the greatest |
| 16 | + common denominator of a list of numbers. |
| 17 | + |
| 18 | +- The `iron-gcd` directory holds the code for the simple web service, |
| 19 | + implemented using the [`iron`] framework, that computes greatest common |
| 20 | + denominators. |
| 21 | + |
| 22 | +- The Mandelbrot plotting program has its own repository, at |
| 23 | + `https://github.com/ProgrammingRust/mandelbrot`. This repository contains |
| 24 | + several branches, each showing a different implementation strategy. The |
| 25 | + `single-threaded` branch holds the code for the single-threaded version, and |
| 26 | + the `bands` branch holds the multi-threaded version. Chapter 19, |
| 27 | + “Concurrency”, shows several other approaches, which appear on other branches; |
| 28 | + see the repository's [README.md][mandel-readme] file for details. |
| 29 | + |
| 30 | +[`iron`]: https://crates.io/crates/iron |
| 31 | + |
| 32 | +## Chapter 8: Crates and Modules |
| 33 | + |
| 34 | +- We did not actually write a fern simulator. Please accept our sincere apology |
| 35 | + for this feckless deception. But the skeleton of modules and definitions we |
| 36 | + show in the book is in the `fern_sim` subdirectory. |
| 37 | + |
| 38 | +## Chapter 9: Structs |
| 39 | + |
| 40 | +- The `queue` directory holds a library that defines the `Queue` type, |
| 41 | + representing a queue of `char` values. |
| 42 | + |
| 43 | +- The `generic-queue` directory holds code for generic `Queue` type. |
| 44 | + |
| 45 | +## Chapter 10: Enums and Patterns |
| 46 | + |
| 47 | +- The `binary-tree` directory holds the source code for the `BinaryTree` type |
| 48 | + that appears in the “Generic Enums” and “Populating a Binary Tree” sections. |
| 49 | + |
| 50 | +## Chapter 12: Operator Overloading |
| 51 | + |
| 52 | +- The `complex` directory holds the `Complex` type used as a running example |
| 53 | + throughout the chapter. |
| 54 | + |
| 55 | +- The `interval` directory holds the `Interval` type for which the book |
| 56 | + implements the `std::cmp::PartialOrd` trait. |
| 57 | + |
| 58 | +## Chapter 14: Closures |
| 59 | + |
| 60 | +- The 'basic-router' directory holds the `BasicRouter` type used as an example |
| 61 | + in the “Callbacks” section. |
| 62 | + |
| 63 | +## Chapter 15: Iterators |
| 64 | + |
| 65 | +- The `binary-tree` directory holds the implementation of the `Iterator` trait |
| 66 | + for the `BinaryTree` type originally defined in the “Enums and Patterns” |
| 67 | + chapter. |
| 68 | + |
| 69 | +## Chapter 17: Strings and Text |
| 70 | + |
| 71 | +- The `complex` directory includes the implementation of the `std::fmt::Display` |
| 72 | + formatting trait for a complex number type, shown in the section “Formatting |
| 73 | + Your Own Types”. |
| 74 | + |
| 75 | +## Chapter 18: Input and Output |
| 76 | + |
| 77 | +- The `grep` directory holds the simple grep-like program shown in the section |
| 78 | + “Reading Lines”. |
| 79 | + |
| 80 | +- The `copy` directory holds the program for copying directory trees from the |
| 81 | + section “Reading Directories”, including the additions shown in the next |
| 82 | + section, “Platform-Specific Features”. |
| 83 | + |
| 84 | +- The `echo-server` directory holds the simple network service shown in the |
| 85 | + “Networking” section. |
| 86 | + |
| 87 | +- The `http-get` directory holds the command-line program that uses the |
| 88 | + `reqwest` crate to carry out an HTTP request. |
| 89 | + |
| 90 | +## Chapter 19: Concurrency |
| 91 | + |
| 92 | +- The search engine used as a running example throughout the book has its own |
| 93 | + repository, at `https://github.com/ProgrammingRust/fingertips`. |
| 94 | + |
| 95 | +- The Mandelbrot set plotter discussed in the section “Revisiting the Mandelbrot |
| 96 | + Set” also has its own repository, at `https://github.com/ProgrammingRust/mandelbrot`. |
| 97 | + The repository includes several branches exploring different implementations; |
| 98 | + see the repository's [README.md][mandel-readme] file for details. |
| 99 | + |
| 100 | +[mandel-readme]: https://github.com/ProgrammingRust/mandelbrot/blob/master/README.md |
| 101 | + |
| 102 | +## Chapter 20: Macros |
| 103 | + |
| 104 | +- The `json-macro` directory holds the definition of the `json!` macro built in |
| 105 | + the section “The json! Macro”. |
| 106 | + |
| 107 | +## Chapter 21: Unsafe Code |
| 108 | + |
| 109 | +- The `ascii` directory holds the `Ascii` type used as an example in the |
| 110 | + sections “Unsafe Blocks” and “Unsafe Functions”. |
| 111 | + |
| 112 | +- The `ref-with-flag` directory holds the `RefWithFlag` type from the “Raw |
| 113 | + Pointers” section. |
| 114 | + |
| 115 | +- The `gap-buffer` directory holds the `GapBuffer` type, used in the “Raw |
| 116 | + Pointers” section to illustrate pointer arithmetic and `std::ptr::read` and |
| 117 | + `std::ptr::write`. |
| 118 | + |
| 119 | +- The `libgit2-rs` and `libgit2-rs-safe` directories contain the two versions of |
| 120 | + the program that uses Rust's foreign function interface to call functions from |
| 121 | + the `libgit2` C library. The version in `libgit2-rs` is written as a single |
| 122 | + giant block of unsafe code, whereas the version in `libgit2-rs-safe` |
| 123 | + implements a safe Rust interface to the same functionality, using Rust's type |
| 124 | + system to enforce libgit2's rules for proper use of the library. |
| 125 | + |
| 126 | + Note that both of these require you to have a copy of `libgit2` present on |
| 127 | + your system. The chapter provides detailed instructions for building the |
| 128 | + correct version, for Linux, macOS, and Microsoft Windows. |
0 commit comments