From 96f06708b0f91abbf7e7826ca83aa48d15745e0a Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 5 Aug 2024 17:52:15 +0200 Subject: [PATCH] Render the book in PDF using `pandoc` and LaTeX. (#126) * Render the book in PDF using `pandoc` and LaTeX. * Fix installs. * Go the apt-get route * Another attempt * Avoid installing twice. * Re-order. * Add more packages. * Minimise deps. Fix link checker. * Missing package. * Missing package. * Missing package. * More packages. * Missing package. * Missing package. * More packages... * Remove. * Fix link checker. * Fix link checker. * Fix path. * Add subtitle. * Avoid running over the right margin. * Avoid running over the right margin. * Formatting --- .github/workflows/ci.yml | 54 ++- Cargo.lock | 356 ++++++++++-------- book/book.toml | 36 +- book/src/02_basic_calculator/10_as_casting.md | 3 +- book/src/03_ticket_v1/01_struct.md | 5 +- book/src/03_ticket_v1/03_modules.md | 2 +- book/src/03_ticket_v1/05_encapsulation.md | 2 +- book/src/03_ticket_v1/06_ownership.md | 18 +- book/src/03_ticket_v1/07_setters.md | 12 +- book/src/03_ticket_v1/08_stack.md | 24 +- book/src/04_traits/05_trait_bounds.md | 7 +- book/src/04_traits/06_str_slice.md | 3 +- book/src/04_traits/08_sized.md | 3 +- book/src/04_traits/09_from.md | 12 +- book/src/04_traits/13_drop.md | 3 +- book/src/05_ticket_v2/01_enum.md | 6 +- book/src/05_ticket_v2/04_if_let.md | 13 +- book/src/05_ticket_v2/06_fallibility.md | 11 +- book/src/05_ticket_v2/07_unwrap.md | 4 +- book/src/07_threads/02_static.md | 6 +- book/src/07_threads/11_locks.md | 6 +- book/src/08_futures/04_future.md | 8 +- book/src/08_futures/07_cancellation.md | 4 +- book/src/going_further.md | 4 +- helpers/mdbook-exercise-linker/src/lib.rs | 12 +- 25 files changed, 401 insertions(+), 213 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2549f5..1d793ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,47 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Install plugin run: cargo install --path helpers/mdbook-exercise-linker + - name: Install mdbook-pandoc and related dependencies + run: | + cargo install mdbook-pandoc --locked --version 0.7.1 + sudo apt-get update + sudo apt-get install -y fonts-noto + + export PANDOC_VERSION=3.3 + curl -LsSf https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz | tar zxf - + echo "$PWD/pandoc-${PANDOC_VERSION}/bin" >> $GITHUB_PATH + shell: bash + - name: Setup TeX Live + uses: teatimeguest/setup-texlive-action@v3 + with: + packages: + scheme-basic + luatex + lualatex-math + luacolor + luatexbase + luaotfload + framed + unicode-math + xcolor + geometry + longtable + booktabs + array + lua-ul + etoolbox + fancyvrb + footnote + selnolig + natbib + csquotes + bookmark + xurl + amsmath + setspace + iftex + - name: Check `tlmgr` version + run: tlmgr --version - uses: taiki-e/install-action@v2 with: tool: mdbook @@ -33,12 +74,19 @@ jobs: --exclude-loopback --require-https --no-progress - book/book - # Upload the book as an artifact + book/book/html/ + # Upload the HTML book as an artifact - uses: actions/upload-artifact@v4 with: name: book - path: book/book + # When you support multiple formats, the output directory changes + # to include the format in its path. + path: book/book/html + # Upload the PDF book as an artifact + - uses: actions/upload-artifact@v4 + with: + name: paperback + path: book/book/pandoc/pdf/100-exercises-to-learn-rust.pdf formatter: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 916ec52..2bf677f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -71,33 +71,33 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.3" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -144,9 +144,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -171,9 +171,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "block-buffer" @@ -201,9 +201,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.9.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", "regex-automata", @@ -231,9 +231,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cancellation" @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.97" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" [[package]] name = "cfg-if" @@ -270,23 +270,23 @@ dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] name = "clap" -version = "4.5.4" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" dependencies = [ "anstream", "anstyle", @@ -297,18 +297,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.2" +version = "4.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +checksum = "a8670053e87c316345e384ca1f3eba3006fc6355ed8b8a1140d104e109e3df34" dependencies = [ "clap", ] [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "client" @@ -323,9 +323,9 @@ version = "0.1.0" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "combinators" @@ -473,9 +473,9 @@ dependencies = [ [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" dependencies = [ "log", "regex", @@ -483,9 +483,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ "anstream", "anstyle", @@ -680,9 +680,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "globset" @@ -826,9 +826,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -844,9 +844,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.28" +version = "0.14.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" dependencies = [ "bytes", "futures-channel", @@ -953,9 +953,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", "hashbrown", @@ -1019,9 +1019,9 @@ version = "0.1.0" [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "iter" @@ -1078,9 +1078,9 @@ version = "0.1.0" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libdbus-sys" @@ -1125,9 +1125,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "mac" @@ -1208,9 +1208,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1220,9 +1220,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mime_guess" -version = "2.0.4" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" dependencies = [ "mime", "unicase", @@ -1230,9 +1230,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -1249,6 +1249,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mio" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + [[package]] name = "modules" version = "0.1.0" @@ -1265,11 +1277,11 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "normpath" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +checksum = "c8911957c4b1549ac0dc74e30db9c8b0e66ddcd6d7acc33098f4c63a64a6d7ed" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1278,7 +1290,7 @@ version = "6.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "crossbeam-channel", "filetime", "fsevent-sys", @@ -1286,7 +1298,7 @@ dependencies = [ "kqueue", "libc", "log", - "mio", + "mio 0.8.11", "walkdir", "windows-sys 0.48.0", ] @@ -1318,21 +1330,11 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" -version = "0.32.2" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" dependencies = [ "memchr", ] @@ -1400,9 +1402,9 @@ version = "0.1.0" [[package]] name = "parking_lot" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -1416,9 +1418,9 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.1", + "redox_syscall 0.5.3", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1443,9 +1445,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" dependencies = [ "memchr", "thiserror", @@ -1454,9 +1456,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a" dependencies = [ "pest", "pest_generator", @@ -1464,9 +1466,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183" dependencies = [ "pest", "pest_meta", @@ -1477,9 +1479,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f" dependencies = [ "once_cell", "pest", @@ -1583,9 +1585,12 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "precomputed-hash" @@ -1595,9 +1600,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1608,7 +1613,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "memchr", "pulldown-cmark-escape", "unicase", @@ -1670,11 +1675,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", ] [[package]] @@ -1683,9 +1688,9 @@ version = "0.1.0" [[package]] name = "regex" -version = "1.10.4" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1695,9 +1700,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -1706,9 +1711,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "resizing" @@ -1741,7 +1746,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -1799,18 +1804,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.202" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.202" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", @@ -1819,11 +1824,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1998,9 +2004,9 @@ version = "0.1.0" [[package]] name = "syn" -version = "2.0.63" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -2017,12 +2023,13 @@ version = "0.1.0" [[package]] name = "tempfile" -version = "3.10.1" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "b8fcd239983515c23a32fb82099f97d0b11b8c72f654ed659363a95c3dad7a53" dependencies = [ "cfg-if", "fastrand", + "once_cell", "rustix", "windows-sys 0.52.0", ] @@ -2050,18 +2057,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -2089,9 +2096,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -2104,28 +2111,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.37.0" +version = "1.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" dependencies = [ "backtrace", "bytes", "libc", - "mio", - "num_cpus", + "mio 1.0.1", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -2293,9 +2299,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -2310,9 +2316,9 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "validation" @@ -2338,9 +2344,9 @@ version = "0.1.0" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "visibility" @@ -2479,11 +2485,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2498,7 +2504,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -2516,7 +2522,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -2536,18 +2551,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -2558,9 +2573,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -2570,9 +2585,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -2582,15 +2597,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -2600,9 +2615,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -2612,9 +2627,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -2624,9 +2639,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -2636,9 +2651,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "without_channels" @@ -2646,3 +2661,24 @@ version = "0.1.0" dependencies = [ "ticket_fields", ] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/book/book.toml b/book/book.toml index ea142b0..10b0188 100644 --- a/book/book.toml +++ b/book/book.toml @@ -1,10 +1,44 @@ [book] -authors = ["Luca Palmieri (Mainmatter)"] +authors = ["Luca Palmieri"] language = "en" multilingual = false src = "src" title = "100 Exercises To Learn Rust" +[output.pandoc] +optional = true +hosted-html = "https://rust-exercises.com/100-exercises/" + +[output.pandoc.profile.pdf] # options to pass to Pandoc (see https://pandoc.org/MANUAL.html) +output-file = "100-exercises-to-learn-rust.pdf" +to = "latex" +highlight-style = "tango" +# We use `lualatext` because, right now, it's the only engine +# that supports fallback fonts, which we need for emojis. +pdf-engine = "lualatex" + +[output.pandoc.profile.pdf.variables] +subtitle = "A hands-on course by Mainmatter" +# You can get these fonts here: https://fonts.google.com/selection?query=noto+color+ +mainfont = "Noto Serif" +sansfont = "Noto Sans" +monofont = "Noto Sans Mono" +mainfontfallback = ["Noto Color Emoji:mode=harf"] +sansfontfallback = ["Noto Color Emoji:mode=harf"] +monofontfallback = [ + "Noto Color Emoji:mode=harf", +] +linkcolor = "blue" +urlcolor = "blue" +urlstyle = "rm" +documentclass = "book" +fontsize = "11pt" +geometry = "papersize={8in,10in},top=2cm,bottom=2cm,left=2.4cm,right=2.4cm" +header-includes = [ + # Reduce font size of code blocks + "\\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\\\\{\\},fontsize=\\small}", +] + [output.html] git-repository-url = "https://github.com/mainmatter/100-exercises-to-learn-rust" diff --git a/book/src/02_basic_calculator/10_as_casting.md b/book/src/02_basic_calculator/10_as_casting.md index 0b8bedf..477f735 100644 --- a/book/src/02_basic_calculator/10_as_casting.md +++ b/book/src/02_basic_calculator/10_as_casting.md @@ -72,7 +72,8 @@ error: literal out of range for `i8` 4 | let a = 255 as i8; | ^^^ | - = note: the literal `255` does not fit into the type `i8` whose range is `-128..=127` + = note: the literal `255` does not fit into the type `i8` + whose range is `-128..=127` = help: consider using the type `u8` instead = note: `#[deny(overflowing_literals)]` on by default ``` diff --git a/book/src/03_ticket_v1/01_struct.md b/book/src/03_ticket_v1/01_struct.md index 9ff9069..1045867 100644 --- a/book/src/03_ticket_v1/01_struct.md +++ b/book/src/03_ticket_v1/01_struct.md @@ -48,7 +48,7 @@ You can create an instance of a struct by specifying the values for each field: // Syntax: { : , ... } let ticket = Ticket { title: "Build a ticket system".into(), - description: "Create a system that can manage tickets across a Kanban board".into(), + description: "A Kanban board".into(), status: "Open".into() }; ``` @@ -130,7 +130,8 @@ let default_config = Configuration::default(); You can use the function call syntax even for methods that take `self` as their first parameter: ```rust -// Function call syntax: ::(, ) +// Function call syntax: +// ::(, ) let is_open = Ticket::is_open(ticket); ``` diff --git a/book/src/03_ticket_v1/03_modules.md b/book/src/03_ticket_v1/03_modules.md index 7a12476..01cc993 100644 --- a/book/src/03_ticket_v1/03_modules.md +++ b/book/src/03_ticket_v1/03_modules.md @@ -81,7 +81,7 @@ You have to use a **path** pointing to the entity you want to access. You can compose the path in various ways: -- starting from the root of the current crate, e.g. `crate::module_1::module_2::MyStruct` +- starting from the root of the current crate, e.g. `crate::module_1::MyStruct` - starting from the parent module, e.g. `super::my_function` - starting from the current module, e.g. `sub_module_1::MyStruct` diff --git a/book/src/03_ticket_v1/05_encapsulation.md b/book/src/03_ticket_v1/05_encapsulation.md index 55557e4..d3930c5 100644 --- a/book/src/03_ticket_v1/05_encapsulation.md +++ b/book/src/03_ticket_v1/05_encapsulation.md @@ -30,7 +30,7 @@ instantiation syntax: // This won't work! let ticket = Ticket { title: "Build a ticket system".into(), - description: "Create a system that can manage tickets across a Kanban board".into(), + description: "A Kanban board".into(), status: "Open".into() }; ``` diff --git a/book/src/03_ticket_v1/06_ownership.md b/book/src/03_ticket_v1/06_ownership.md index cc4e673..f0cb5cf 100644 --- a/book/src/03_ticket_v1/06_ownership.md +++ b/book/src/03_ticket_v1/06_ownership.md @@ -44,9 +44,11 @@ error[E0382]: use of moved value: `ticket` | -------- `ticket` moved due to this method call ... 30 | println!("Your next task is: {}", ticket.title()); - | ^^^^^^ value used here after move + | ^^^^^^ + | value used here after move | -note: `Ticket::status` takes ownership of the receiver `self`, which moves `ticket` +note: `Ticket::status` takes ownership of the receiver `self`, + which moves `ticket` --> src/main.rs:12:23 | 12 | pub fn status(self) -> String { @@ -130,9 +132,11 @@ error[E0382]: use of moved value: `ticket` | -------- `ticket` moved due to this method call ... 30 | println!("Your next task is: {}", ticket.title()); - | ^^^^^^ value used here after move + | ^^^^^^ + | value used here after move | -note: `Ticket::status` takes ownership of the receiver `self`, which moves `ticket` +note: `Ticket::status` takes ownership of the receiver `self`, + which moves `ticket` --> src/main.rs:12:23 | 12 | pub fn status(self) -> String { @@ -199,8 +203,10 @@ fn main() { active: true, }; // `b` is a reference to the `version` field of `config`. - // The type of `b` is `&u32`, since it contains a reference to a `u32` value. - // We create a reference by borrowing `config.version`, using the `&` operator. + // The type of `b` is `&u32`, since it contains a reference to + // a `u32` value. + // We create a reference by borrowing `config.version`, using + // the `&` operator. // Same symbol (`&`), different meaning depending on the context! let b: &u32 = &config.version; // ^ The type annotation is not necessary, diff --git a/book/src/03_ticket_v1/07_setters.md b/book/src/03_ticket_v1/07_setters.md index 81a81f2..caaf92f 100644 --- a/book/src/03_ticket_v1/07_setters.md +++ b/book/src/03_ticket_v1/07_setters.md @@ -50,7 +50,11 @@ It takes ownership of `self`, changes the title, and returns the modified `Ticke This is how you'd use it: ```rust -let ticket = Ticket::new("Title".into(), "Description".into(), "To-Do".into()); +let ticket = Ticket::new( + "Title".into(), + "Description".into(), + "To-Do".into() +); let ticket = ticket.set_title("New title".into()); ``` @@ -88,7 +92,11 @@ Nothing is returned. You'd use it like this: ```rust -let mut ticket = Ticket::new("Title".into(), "Description".into(), "To-Do".into()); +let mut ticket = Ticket::new( + "Title".into(), + "Description".into(), + "To-Do".into() +); ticket.set_title("New title".into()); // Use the modified ticket diff --git a/book/src/03_ticket_v1/08_stack.md b/book/src/03_ticket_v1/08_stack.md index 550e91b..b95dd6d 100644 --- a/book/src/03_ticket_v1/08_stack.md +++ b/book/src/03_ticket_v1/08_stack.md @@ -18,11 +18,25 @@ the function's arguments, local variables and a few "bookkeeping" values.\ When the function returns, the stack frame is popped off the stack[^stack-overflow]. ```text - +-----------------+ - func2 | frame for func2 | func2 -+-----------------+ is called +-----------------+ returns +-----------------+ -| frame for func1 | -----------> | frame for func1 | ---------> | frame for func1 | -+-----------------+ +-----------------+ +-----------------+ ++-----------------+ +| frame for func1 | ++-----------------+ + | + | func2 is + | called + v ++-----------------+ +| frame for func2 | ++-----------------+ +| frame for func1 | ++-----------------+ + | + | func2 + | returns + v ++-----------------+ +| frame for func1 | ++-----------------+ ``` From an operational point of view, stack allocation/de-allocation is **very fast**.\ diff --git a/book/src/04_traits/05_trait_bounds.md b/book/src/04_traits/05_trait_bounds.md index a3e3f73..53f92e8 100644 --- a/book/src/04_traits/05_trait_bounds.md +++ b/book/src/04_traits/05_trait_bounds.md @@ -94,7 +94,8 @@ fn print_if_even(n: T) { This code won't compile: ```text -error[E0599]: no method named `is_even` found for type parameter `T` in the current scope +error[E0599]: no method named `is_even` found for type parameter `T` + in the current scope --> src/lib.rs:2:10 | 1 | fn print_if_even(n: T) { @@ -106,7 +107,9 @@ error[E0277]: `T` doesn't implement `Debug` --> src/lib.rs:3:19 | 3 | println!("{n:?} is even"); - | ^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^ + | `T` cannot be formatted using `{:?}` because + | it doesn't implement `Debug` | help: consider restricting type parameter `T` | diff --git a/book/src/04_traits/06_str_slice.md b/book/src/04_traits/06_str_slice.md index e957e3d..cae9a55 100644 --- a/book/src/04_traits/06_str_slice.md +++ b/book/src/04_traits/06_str_slice.md @@ -72,7 +72,8 @@ You can, for example, create a `&str` from a `String` like this: ```rust let mut s = String::with_capacity(5); s.push_str("Hello"); -// Create a string slice reference from the `String`, skipping the first byte. +// Create a string slice reference from the `String`, +// skipping the first byte. let slice: &str = &s[1..]; ``` diff --git a/book/src/04_traits/08_sized.md b/book/src/04_traits/08_sized.md index 585b4c6..badfebe 100644 --- a/book/src/04_traits/08_sized.md +++ b/book/src/04_traits/08_sized.md @@ -11,7 +11,8 @@ to the pointer: the length of the slice it points to. Going back to the example ```rust let mut s = String::with_capacity(5); s.push_str("Hello"); -// Create a string slice reference from the `String`, skipping the first byte. +// Create a string slice reference from the `String`, +// skipping the first byte. let slice: &str = &s[1..]; ``` diff --git a/book/src/04_traits/09_from.md b/book/src/04_traits/09_from.md index 3006dba..3fa6193 100644 --- a/book/src/04_traits/09_from.md +++ b/book/src/04_traits/09_from.md @@ -3,7 +3,11 @@ Let's go back to where our string journey started: ```rust -let ticket = Ticket::new("A title".into(), "A description".into(), "To-Do".into()); +let ticket = Ticket::new( + "A title".into(), + "A description".into(), + "To-Do".into() +); ``` We now know enough to start unpacking what `.into()` is doing here. @@ -14,7 +18,11 @@ This is the signature of the `new` method: ```rust impl Ticket { - pub fn new(title: String, description: String, status: String) -> Self { + pub fn new( + title: String, + description: String, + status: String + ) -> Self { // [...] } } diff --git a/book/src/04_traits/13_drop.md b/book/src/04_traits/13_drop.md index 2f4219a..95352a9 100644 --- a/book/src/04_traits/13_drop.md +++ b/book/src/04_traits/13_drop.md @@ -44,7 +44,8 @@ impl Drop for MyType { The compiler will complain with this error message: ```text -error[E0184]: the trait `Copy` cannot be implemented for this type; the type has a destructor +error[E0184]: the trait `Copy` cannot be implemented for this type; + the type has a destructor --> src/lib.rs:2:17 | 2 | #[derive(Clone, Copy)] diff --git a/book/src/05_ticket_v2/01_enum.md b/book/src/05_ticket_v2/01_enum.md index 6fa9657..79000af 100644 --- a/book/src/05_ticket_v2/01_enum.md +++ b/book/src/05_ticket_v2/01_enum.md @@ -14,7 +14,11 @@ pub struct Ticket { } impl Ticket { - pub fn new(title: String, description: String, status: String) -> Self { + pub fn new( + title: String, + description: String, + status: String + ) -> Self { // [...] } } diff --git a/book/src/05_ticket_v2/04_if_let.md b/book/src/05_ticket_v2/04_if_let.md index 399babf..4fe8be0 100644 --- a/book/src/05_ticket_v2/04_if_let.md +++ b/book/src/05_ticket_v2/04_if_let.md @@ -8,7 +8,10 @@ impl Ticket { match &self.status { Status::InProgress { assigned_to } => assigned_to, Status::Done | Status::ToDo => { - panic!("Only `In-Progress` tickets can be assigned to someone") + panic!( + "Only `In-Progress` tickets can be \ + assigned to someone" + ) } } } @@ -33,7 +36,9 @@ impl Ticket { if let Status::InProgress { assigned_to } = &self.status { assigned_to } else { - panic!("Only `In-Progress` tickets can be assigned to someone"); + panic!( + "Only `In-Progress` tickets can be assigned to someone" + ); } } } @@ -48,7 +53,9 @@ you can use the `let/else` construct: impl Ticket { pub fn assigned_to(&self) -> &str { let Status::InProgress { assigned_to } = &self.status else { - panic!("Only `In-Progress` tickets can be assigned to someone"); + panic!( + "Only `In-Progress` tickets can be assigned to someone" + ); }; assigned_to } diff --git a/book/src/05_ticket_v2/06_fallibility.md b/book/src/05_ticket_v2/06_fallibility.md index d3b4c37..213a99d 100644 --- a/book/src/05_ticket_v2/06_fallibility.md +++ b/book/src/05_ticket_v2/06_fallibility.md @@ -4,7 +4,11 @@ Let's revisit the `Ticket::new` function from the previous exercise: ```rust impl Ticket { - pub fn new(title: String, description: String, status: Status) -> Ticket { + pub fn new( + title: String, + description: String, + status: Status + ) -> Ticket { if title.is_empty() { panic!("Title cannot be empty"); } @@ -70,8 +74,9 @@ Rust, with `Result`, forces you to **encode fallibility in the function's signat If a function can fail (and you want the caller to have a shot at handling the error), it must return a `Result`. ```rust -// Just by looking at the signature, you know that this function can fail. -// You can also inspect `ParseIntError` to see what kind of failures to expect. +// Just by looking at the signature, you know that this function +// can fail. You can also inspect `ParseIntError` to see what +// kind of failures to expect. fn parse_int(s: &str) -> Result { // ... } diff --git a/book/src/05_ticket_v2/07_unwrap.md b/book/src/05_ticket_v2/07_unwrap.md index cb793ba..ba67eed 100644 --- a/book/src/05_ticket_v2/07_unwrap.md +++ b/book/src/05_ticket_v2/07_unwrap.md @@ -14,8 +14,8 @@ fn parse_int(s: &str) -> Result { } // This won't compile: we're not handling the error case. -// We must either use `match` or one of the combinators provided by `Result` -// to "unwrap" the success value or handle the error. +// We must either use `match` or one of the combinators provided by +// `Result` to "unwrap" the success value or handle the error. let number = parse_int("42") + 2; ``` diff --git a/book/src/07_threads/02_static.md b/book/src/07_threads/02_static.md index 25a7644..ebc5139 100644 --- a/book/src/07_threads/02_static.md +++ b/book/src/07_threads/02_static.md @@ -11,9 +11,9 @@ error[E0597]: `v` does not live long enough ... 15 | let right = &v[split_point..]; | ^ borrowed value does not live long enough -16 | let left_handle = thread::spawn(move || left.iter().sum::()); - | ------------------------------------------------ - argument requires that `v` is borrowed for `'static` +16 | let left_handle = spawn(move || left.iter().sum::()); + | -------------------------------- + argument requires that `v` is borrowed for `'static` 19 | } | - `v` dropped here while still borrowed ``` diff --git a/book/src/07_threads/11_locks.md b/book/src/07_threads/11_locks.md index 519cc95..3833bc1 100644 --- a/book/src/07_threads/11_locks.md +++ b/book/src/07_threads/11_locks.md @@ -122,8 +122,10 @@ error[E0277]: `MutexGuard<'_, i32>` cannot be sent between threads safely 12 | | }); | |_^ `MutexGuard<'_, i32>` cannot be sent between threads safely | - = help: the trait `Send` is not implemented for `MutexGuard<'_, i32>`, which is required by `{closure@src/main.rs:10:7: 10:14}: Send` - = note: required for `std::sync::mpsc::Receiver>` to implement `Send` + = help: the trait `Send` is not implemented for `MutexGuard<'_, i32>`, + which is required by `{closure@src/main.rs:10:7: 10:14}: Send` + = note: required for `std::sync::mpsc::Receiver>` + to implement `Send` note: required because it's used within this closure ``` diff --git a/book/src/08_futures/04_future.md b/book/src/08_futures/04_future.md index df2feb1..0e0a012 100644 --- a/book/src/08_futures/04_future.md +++ b/book/src/08_futures/04_future.md @@ -55,7 +55,8 @@ note: future is not `Send` as this value is used across an await | -------- has type `Rc` which is not `Send` 12 | // A `.await` point 13 | yield_now().await; - | ^^^^^ await occurs here, with `non_send` maybe used later + | ^^^^^ + | await occurs here, with `non_send` maybe used later note: required by a bound in `tokio::spawn` | 164 | pub fn spawn(future: F) -> JoinHandle @@ -84,7 +85,10 @@ trait Future { type Output; // Ignore `Pin` and `Context` for now - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; + fn poll( + self: Pin<&mut Self>, + cx: &mut Context<'_> + ) -> Poll; } ``` diff --git a/book/src/08_futures/07_cancellation.md b/book/src/08_futures/07_cancellation.md index 33a3163..197e605 100644 --- a/book/src/08_futures/07_cancellation.md +++ b/book/src/08_futures/07_cancellation.md @@ -105,5 +105,5 @@ async fn run() { Check out [`select!`'s documentation](https://tokio.rs/tokio/tutorial/select) for more details.\ If you need to interleave two asynchronous streams of data (e.g. a socket and a channel), prefer using [`StreamExt::merge`](https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.merge) instead. -- Rather than "abrupt" cancellation, it can be preferable to rely - on [`CancellationToken`](https://docs.rs/tokio-util/latest/tokio_util/sync/struct.CancellationToken.html). +- A [`CancellationToken`](https://docs.rs/tokio-util/latest/tokio_util/sync/struct.CancellationToken.html) may be + preferable to `JoinHandle::abort` in some cases. diff --git a/book/src/going_further.md b/book/src/going_further.md index 44e5d08..07afaaf 100644 --- a/book/src/going_further.md +++ b/book/src/going_further.md @@ -48,5 +48,5 @@ check out the [Embedded Rust book](https://docs.rust-embedded.org/book/). You can then find resources on key topics that cut across domains.\ For testing, check out -["Advanced testing, going beyond the basics"](https://github.com/mainmatter/rust-advanced-testing-workshop).\ -For telemetry, check out ["You can't fix what you can't see"](https://github.com/mainmatter/rust-telemetry-workshop). +["Advanced testing, going beyond the basics"](https://rust-exercises.com/advanced-testing/).\ +For telemetry, check out ["You can't fix what you can't see"](https://rust-exercises.com/telemetry/). diff --git a/helpers/mdbook-exercise-linker/src/lib.rs b/helpers/mdbook-exercise-linker/src/lib.rs index 0f4686e..4f7fb1f 100644 --- a/helpers/mdbook-exercise-linker/src/lib.rs +++ b/helpers/mdbook-exercise-linker/src/lib.rs @@ -33,7 +33,7 @@ impl Preprocessor for ExerciseLinker { book.sections .iter_mut() - .for_each(|i| process_book_item(i, &root_url)); + .for_each(|i| process_book_item(i, &ctx.renderer, &root_url)); Ok(book) } @@ -42,11 +42,11 @@ impl Preprocessor for ExerciseLinker { } } -fn process_book_item(item: &mut BookItem, root_url: &str) { +fn process_book_item(item: &mut BookItem, renderer: &str, root_url: &str) { match item { BookItem::Chapter(chapter) => { chapter.sub_items.iter_mut().for_each(|item| { - process_book_item(item, root_url); + process_book_item(item, renderer, root_url); }); let Some(source_path) = &chapter.source_path else { @@ -61,10 +61,14 @@ fn process_book_item(item: &mut BookItem, root_url: &str) { let exercise_path = source_path.strip_suffix(".md").unwrap(); let link_section = format!( - "\n## Exercise\n\nThe exercise for this section is located in [`{exercise_path}`]({})", + "\n## Exercise\n\nThe exercise for this section is located in [`{exercise_path}`]({})\n", format!("{}/{}", root_url, exercise_path) ); chapter.content.push_str(&link_section); + + if renderer == "pandoc" { + chapter.content.push_str("`\\newpage`{=latex}\n"); + } } BookItem::Separator => {} BookItem::PartTitle(_) => {} -- 2.45.2