├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── amnesia ├── Cargo.toml └── src │ └── main.rs ├── async_threaded ├── Cargo.toml └── src │ └── main.rs ├── boxes ├── Cargo.toml └── src │ └── main.rs ├── byte_sized ├── Cargo.toml └── src │ └── main.rs ├── byte_sized_wrap ├── Cargo.toml └── src │ └── main.rs ├── const_loop ├── Cargo.toml └── src │ └── main.rs ├── const_loop_works ├── Cargo.toml └── src │ └── main.rs ├── double_or_nothing ├── Cargo.toml └── src │ └── main.rs ├── double_or_nothing_working ├── Cargo.toml └── src │ └── main.rs ├── gordian_knot ├── Cargo.toml └── src │ └── main.rs ├── hello_bonjour ├── Cargo.toml └── src │ └── main.rs ├── hello_bonjour_const ├── Cargo.toml └── src │ └── main.rs ├── hello_bonjour_static ├── Cargo.toml └── src │ └── main.rs ├── linked_list ├── Cargo.toml └── src │ └── main.rs ├── misc └── shadow_example.rs ├── morse_code ├── Cargo.toml └── src │ └── main.rs ├── mutable_immutable ├── Cargo.toml └── src │ └── main.rs ├── out_of_order ├── Cargo.toml └── src │ └── main.rs ├── quack ├── Cargo.toml └── src │ └── main.rs ├── reboot_universe ├── Cargo.toml └── src │ └── main.rs ├── reverse_polarity ├── Cargo.toml └── src │ └── main.rs ├── sleepless ├── Cargo.toml └── src │ └── main.rs ├── src └── main.rs ├── standard_input ├── Cargo.toml └── src │ └── main.rs ├── string_length ├── Cargo.toml └── src │ └── main.rs ├── structure_sizing ├── Cargo.toml └── src │ └── main.rs ├── there_and_back ├── Cargo.toml └── src │ └── main.rs ├── three_and_a_bit ├── Cargo.toml └── src │ └── main.rs ├── type_conversion ├── Cargo.toml └── src │ └── main.rs ├── vec_size ├── Cargo.toml └── src │ └── main.rs ├── waiting_for_godot ├── Cargo.toml └── src │ └── main.rs └── x_marks_spot ├── Cargo.toml └── src └── main.rs /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "amnesia" 7 | version = "0.1.0" 8 | 9 | [[package]] 10 | name = "async_threaded" 11 | version = "0.1.0" 12 | 13 | [[package]] 14 | name = "autocfg" 15 | version = "1.0.1" 16 | source = "registry+https://github.com/rust-lang/crates.io-index" 17 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 18 | 19 | [[package]] 20 | name = "bitflags" 21 | version = "1.2.1" 22 | source = "registry+https://github.com/rust-lang/crates.io-index" 23 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 24 | 25 | [[package]] 26 | name = "boxes" 27 | version = "0.1.0" 28 | 29 | [[package]] 30 | name = "byte_sized" 31 | version = "0.1.0" 32 | 33 | [[package]] 34 | name = "byte_sized_wrap" 35 | version = "0.1.0" 36 | 37 | [[package]] 38 | name = "bytes" 39 | version = "1.0.1" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" 42 | 43 | [[package]] 44 | name = "cfg-if" 45 | version = "1.0.0" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 48 | 49 | [[package]] 50 | name = "const_loop" 51 | version = "0.1.0" 52 | 53 | [[package]] 54 | name = "const_loop_works" 55 | version = "0.1.0" 56 | 57 | [[package]] 58 | name = "double_or_nothing" 59 | version = "0.1.0" 60 | 61 | [[package]] 62 | name = "double_or_nothing_working" 63 | version = "0.1.0" 64 | 65 | [[package]] 66 | name = "gordian_knot" 67 | version = "0.1.0" 68 | 69 | [[package]] 70 | name = "hello_bonjour" 71 | version = "0.1.0" 72 | 73 | [[package]] 74 | name = "hello_bonjour_const" 75 | version = "0.1.0" 76 | 77 | [[package]] 78 | name = "hello_bonjour_static" 79 | version = "0.1.0" 80 | 81 | [[package]] 82 | name = "hermit-abi" 83 | version = "0.1.18" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" 86 | dependencies = [ 87 | "libc", 88 | ] 89 | 90 | [[package]] 91 | name = "instant" 92 | version = "0.1.9" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" 95 | dependencies = [ 96 | "cfg-if", 97 | ] 98 | 99 | [[package]] 100 | name = "libc" 101 | version = "0.2.97" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" 104 | 105 | [[package]] 106 | name = "linked_list" 107 | version = "0.1.0" 108 | 109 | [[package]] 110 | name = "lock_api" 111 | version = "0.4.4" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" 114 | dependencies = [ 115 | "scopeguard", 116 | ] 117 | 118 | [[package]] 119 | name = "log" 120 | version = "0.4.14" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 123 | dependencies = [ 124 | "cfg-if", 125 | ] 126 | 127 | [[package]] 128 | name = "memchr" 129 | version = "2.4.0" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" 132 | 133 | [[package]] 134 | name = "mio" 135 | version = "0.7.13" 136 | source = "registry+https://github.com/rust-lang/crates.io-index" 137 | checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" 138 | dependencies = [ 139 | "libc", 140 | "log", 141 | "miow", 142 | "ntapi", 143 | "winapi", 144 | ] 145 | 146 | [[package]] 147 | name = "miow" 148 | version = "0.3.7" 149 | source = "registry+https://github.com/rust-lang/crates.io-index" 150 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 151 | dependencies = [ 152 | "winapi", 153 | ] 154 | 155 | [[package]] 156 | name = "morse_code" 157 | version = "0.1.0" 158 | 159 | [[package]] 160 | name = "mutable_immutable" 161 | version = "0.1.0" 162 | 163 | [[package]] 164 | name = "ntapi" 165 | version = "0.3.6" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" 168 | dependencies = [ 169 | "winapi", 170 | ] 171 | 172 | [[package]] 173 | name = "num_cpus" 174 | version = "1.13.0" 175 | source = "registry+https://github.com/rust-lang/crates.io-index" 176 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 177 | dependencies = [ 178 | "hermit-abi", 179 | "libc", 180 | ] 181 | 182 | [[package]] 183 | name = "once_cell" 184 | version = "1.8.0" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" 187 | 188 | [[package]] 189 | name = "out_of_order" 190 | version = "0.1.0" 191 | 192 | [[package]] 193 | name = "parking_lot" 194 | version = "0.11.1" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" 197 | dependencies = [ 198 | "instant", 199 | "lock_api", 200 | "parking_lot_core", 201 | ] 202 | 203 | [[package]] 204 | name = "parking_lot_core" 205 | version = "0.8.3" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" 208 | dependencies = [ 209 | "cfg-if", 210 | "instant", 211 | "libc", 212 | "redox_syscall", 213 | "smallvec", 214 | "winapi", 215 | ] 216 | 217 | [[package]] 218 | name = "pin-project-lite" 219 | version = "0.2.6" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" 222 | 223 | [[package]] 224 | name = "proc-macro2" 225 | version = "1.0.27" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" 228 | dependencies = [ 229 | "unicode-xid", 230 | ] 231 | 232 | [[package]] 233 | name = "quack" 234 | version = "0.1.0" 235 | 236 | [[package]] 237 | name = "quote" 238 | version = "1.0.9" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 241 | dependencies = [ 242 | "proc-macro2", 243 | ] 244 | 245 | [[package]] 246 | name = "reboot_universe" 247 | version = "0.1.0" 248 | 249 | [[package]] 250 | name = "redox_syscall" 251 | version = "0.2.9" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" 254 | dependencies = [ 255 | "bitflags", 256 | ] 257 | 258 | [[package]] 259 | name = "reverse_polarity" 260 | version = "0.1.0" 261 | 262 | [[package]] 263 | name = "scopeguard" 264 | version = "1.1.0" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 267 | 268 | [[package]] 269 | name = "signal-hook-registry" 270 | version = "1.4.0" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" 273 | dependencies = [ 274 | "libc", 275 | ] 276 | 277 | [[package]] 278 | name = "sleepless" 279 | version = "0.1.0" 280 | dependencies = [ 281 | "tokio", 282 | ] 283 | 284 | [[package]] 285 | name = "smallvec" 286 | version = "1.6.1" 287 | source = "registry+https://github.com/rust-lang/crates.io-index" 288 | checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" 289 | 290 | [[package]] 291 | name = "standard_input" 292 | version = "0.1.0" 293 | 294 | [[package]] 295 | name = "string_length" 296 | version = "0.1.0" 297 | 298 | [[package]] 299 | name = "structure_sizing" 300 | version = "0.1.0" 301 | 302 | [[package]] 303 | name = "syn" 304 | version = "1.0.73" 305 | source = "registry+https://github.com/rust-lang/crates.io-index" 306 | checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" 307 | dependencies = [ 308 | "proc-macro2", 309 | "quote", 310 | "unicode-xid", 311 | ] 312 | 313 | [[package]] 314 | name = "teasers" 315 | version = "0.1.0" 316 | 317 | [[package]] 318 | name = "there_and_back" 319 | version = "0.1.0" 320 | 321 | [[package]] 322 | name = "three_and_a_bit" 323 | version = "0.1.0" 324 | 325 | [[package]] 326 | name = "tokio" 327 | version = "1.7.0" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "c79ba603c337335df6ba6dd6afc38c38a7d5e1b0c871678439ea973cd62a118e" 330 | dependencies = [ 331 | "autocfg", 332 | "bytes", 333 | "libc", 334 | "memchr", 335 | "mio", 336 | "num_cpus", 337 | "once_cell", 338 | "parking_lot", 339 | "pin-project-lite", 340 | "signal-hook-registry", 341 | "tokio-macros", 342 | "winapi", 343 | ] 344 | 345 | [[package]] 346 | name = "tokio-macros" 347 | version = "1.2.0" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" 350 | dependencies = [ 351 | "proc-macro2", 352 | "quote", 353 | "syn", 354 | ] 355 | 356 | [[package]] 357 | name = "type_conversion" 358 | version = "0.1.0" 359 | 360 | [[package]] 361 | name = "unicode-xid" 362 | version = "0.2.2" 363 | source = "registry+https://github.com/rust-lang/crates.io-index" 364 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 365 | 366 | [[package]] 367 | name = "vec_size" 368 | version = "0.1.0" 369 | 370 | [[package]] 371 | name = "waiting_for_godot" 372 | version = "0.1.0" 373 | dependencies = [ 374 | "tokio", 375 | ] 376 | 377 | [[package]] 378 | name = "winapi" 379 | version = "0.3.9" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 382 | dependencies = [ 383 | "winapi-i686-pc-windows-gnu", 384 | "winapi-x86_64-pc-windows-gnu", 385 | ] 386 | 387 | [[package]] 388 | name = "winapi-i686-pc-windows-gnu" 389 | version = "0.4.0" 390 | source = "registry+https://github.com/rust-lang/crates.io-index" 391 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 392 | 393 | [[package]] 394 | name = "winapi-x86_64-pc-windows-gnu" 395 | version = "0.4.0" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 398 | 399 | [[package]] 400 | name = "x_marks_spot" 401 | version = "0.1.0" 402 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "teasers" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | 9 | [workspace] 10 | members = [ 11 | "byte_sized", 12 | "byte_sized_wrap", 13 | "three_and_a_bit", 14 | "reboot_universe", 15 | "out_of_order", 16 | "standard_input", 17 | "string_length", 18 | "x_marks_spot", 19 | "type_conversion", 20 | "there_and_back", 21 | "quack", 22 | "structure_sizing", 23 | "mutable_immutable", 24 | "sleepless", 25 | "async_threaded", 26 | "waiting_for_godot", 27 | "reverse_polarity", 28 | "double_or_nothing", 29 | "double_or_nothing_working", 30 | "hello_bonjour", 31 | "hello_bonjour_static", 32 | "hello_bonjour_const", 33 | "amnesia", 34 | "const_loop", 35 | "const_loop_works", 36 | "boxes", 37 | "vec_size", 38 | "gordian_knot", 39 | "morse_code", 40 | "linked_list", 41 | ] 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Herbert "TheBracket" 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rust Brain Teasers 2 | 3 | This repo contains source code from my second book, *Rust Brain Teasers*. Ever puzzle is included, as well as expanded versions for when a chapter includes a solution. 4 | 5 | ## About Rust Brain Teasers 6 | 7 | The Rust programming language is consistent and does its best to avoid surprising the programmer. Like all languages, though, Rust still has its quirks. But these quirks present a teaching opportunity. In this book, you’ll work through a series of brain teasers that will challenge your understanding of Rust. By understanding the gaps in your knowledge, you can become better at what you do and avoid mistakes. Many of the teasers in this book come from the author’s own experience creating software. Others derive from commonly asked questions in the Rust community. Regardless of their origin, these brain teasers are fun, and let’s face it: who doesn’t love a good puzzle, right? 8 | 9 | What better way to exercise your brain and increase your Rust programming knowledge than with a collection of dynamic brain teasers? As you read through each of these puzzles and try to work out the answers, you’ll not only learn about Rust’s unique quirks and peculiarities, you’ll also have loads of fun along the way. 10 | 11 | Dive right in and get started with example code and sample problems that cover numbers and text, shadowing and memory, and everything in between. Try to figure out why a particular program won’t compile, why it produces unexpected output, or why it panics and terminates with an error message. Once you’ve run the code and read the answer, it’s time to get to the heart of the matter with a detailed explanation. Learn why a program produced the result it did, and discover how similar issues might affect the code you write in your own programs, even in production. Sourced from engaging discussions within the Rust community, real-world problems, and even reader feedback, these challenges will certainly surprise, enlighten, and entertain you. 12 | 13 | Are you ready to experience Rust like never before? Then sharpen your brain and get ready for a challenge! 14 | 15 | ## Where to Buy? 16 | 17 | *Rust Brain Teasers* is available directly from the Pragmatic Programmers. [You can buy it directly from the publisher, here](https://pragprog.com/titles/hwrustbrain/rust-brain-teasers/). 18 | 19 | PragProg primarily ship to the USA. In other parts of the world, you can use Amazon. I've tried to collate a few places from which you can buy *Rust Brain Teasers*: 20 | 21 | * *Rust Brain Teasers* is on [Amazon.com](https://www.amazon.com/Rust-Brain-Teasers-Exercise-Your/dp/1680509179). 22 | * [Amazon Canada](https://www.amazon.ca/Rust-Brain-Teasers-Exercise-Your/dp/1680509179) 23 | * [Amazon UK](https://www.amazon.co.uk/Rust-Brain-Teasers-Exercise-Your/dp/1680509179) 24 | * [Amazon Deutschland](https://www.amazon.de/Rust-Brain-Teasers-Exercise-Your/dp/1680509179) 25 | * [Amazon France](https://www.amazon.fr/Rust-Brain-Teasers-Exercise-Your/dp/1680509179) 26 | * [Amazon Japan](https://www.amazon.co.jp/Rust-Brain-Teasers-Exercise-Your/dp/1680509179) 27 | * [Amazon Brazil](https://www.amazon.com.br/Rust-Brain-Teasers-Exercise-Your/dp/1680509179) 28 | * *Rust Brain Teasers* is available at [Barnes and Noble](https://www.barnesandnoble.com/w/rust-brain-teasers-herbert-wolverson/1141092328?ean=9781680509175) 29 | * [Waterstones](https://www.waterstones.com/book/rust-brain-teasers/herbert-wolverson/9781680509175) 30 | * [WH Smith](https://www.whsmith.co.uk/products/rust-brain-teasers-exercise-your-mind/herbert-wolverson/paperback/9781680509175.html) 31 | * In Australia, you can order from [Angus & Robertson](https://www.angusrobertson.com.au/books/rust-brain-teasers-herbert-wolverson/p/9781680509175?searchTerm=rust%20brain%20teasers) 32 | * Also in Australia, [Booktopia](https://www.booktopia.com.au/rust-brain-teasers-herbert-wolverson/book/9781680509175.html) 33 | * [Book People](https://www.bookpeople.com/book/9781680509175) sell *Rust Brain Teasers* around the world. 34 | 35 | You can also ask your local library or favorite independent bookstore for ISBN: `978-1680509175`. 36 | 37 | # Source Code by Puzzle 38 | 39 | * [Three and a Bit](https://github.com/thebracket/rust_brain_teasers/tree/main/three_and_a_bit) 40 | * [Non-standard Input](https://github.com/thebracket/rust_brain_teasers/tree/main/standard_input) 41 | * [Type Conversion](https://github.com/thebracket/rust_brain_teasers/tree/main/type_conversion) 42 | * [Byte-Sized Chunks](https://github.com/thebracket/rust_brain_teasers/tree/main/byte_sized) 43 | * [With Wrapping](https://github.com/thebracket/rust_brain_teasers/tree/main/byte_sized_wrap) 44 | * [How Long is a String?](https://github.com/thebracket/rust_brain_teasers/tree/main/string_length) 45 | * [Please Reboot the Universe](https://github.com/thebracket/rust_brain_teasers/tree/main/reboot_universe) 46 | * [There and Back Again](https://github.com/thebracket/rust_brain_teasers/tree/main/there_and_back) 47 | * [Walks Like a Duck, Quacks like a Duck](https://github.com/thebracket/rust_brain_teasers/tree/main/quack) 48 | * [Out of Order](https://github.com/thebracket/rust_brain_teasers/tree/main/out_of_order) 49 | * [X Marks the Spot](https://github.com/thebracket/rust_brain_teasers/tree/main/x_marks_spot) 50 | * [Stacking Boxes](https://github.com/thebracket/rust_brain_teasers/tree/main/boxes) 51 | * [Amnesia](https://github.com/thebracket/rust_brain_teasers/tree/main/amnesia) 52 | * [Reverse the Polarity of the Neutron Flow](https://github.com/thebracket/rust_brain_teasers/tree/main/reverse_polarity) 53 | * [Structure Sizing](https://github.com/thebracket/rust_brain_teasers/tree/main/structure_sizing) 54 | * [To Infinity](https://github.com/thebracket/rust_brain_teasers/tree/main/linked_list) 55 | * [Double or Nothing](https://github.com/thebracket/rust_brain_teasers/tree/main/double_or_nothing) 56 | * [Solution](https://github.com/thebracket/rust_brain_teasers/tree/main/double_or_nothing_working) 57 | * [How Long is a Vector?](https://github.com/thebracket/rust_brain_teasers/tree/main/vec_size) 58 | * [Mutable Immutables](https://github.com/thebracket/rust_brain_teasers/tree/main/mutable_immutable) 59 | * [Sleepless in Tokio](https://github.com/thebracket/rust_brain_teasers/tree/main/sleepless) 60 | * [Hello, Bonjour](https://github.com/thebracket/rust_brain_teasers/tree/main/hello_bonjour) 61 | * [With Constants](https://github.com/thebracket/rust_brain_teasers/tree/main/hello_bonjour_const) 62 | * [With Static Binding](https://github.com/thebracket/rust_brain_teasers/tree/main/hello_bonjour_static) 63 | * [Tying a Gourdian Knot](https://github.com/thebracket/rust_brain_teasers/tree/main/gordian_knot) 64 | * [Waiting for Godot](https://github.com/thebracket/rust_brain_teasers/tree/main/waiting_for_godot) 65 | * [Constant Loops](https://github.com/thebracket/rust_brain_teasers/tree/main/const_loop) 66 | * [Solution](https://github.com/thebracket/rust_brain_teasers/tree/main/const_loop_works) 67 | * [Home on the Range](https://github.com/thebracket/rust_brain_teasers/tree/main/morse_code) 68 | 69 | -------------------------------------------------------------------------------- /amnesia/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "amnesia" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /amnesia/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | loop { 3 | let buffer = (0..1000).collect::>(); 4 | std::mem::forget(buffer); 5 | print!("."); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /async_threaded/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "async_threaded" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /async_threaded/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::thread; 2 | use std::time::Duration; 3 | 4 | fn count_and_wait(n: u64) -> u64 { 5 | println!("Starting {}", n); 6 | std::thread::sleep(Duration::from_millis(n * 100)); 7 | println!("Returning {}", n); 8 | n 9 | } 10 | 11 | fn main() -> Result<(), Box> { 12 | let a = thread::spawn(|| count_and_wait(1)); 13 | let b = thread::spawn(|| count_and_wait(2)); 14 | let c = thread::spawn(|| count_and_wait(3)); 15 | a.join().unwrap(); 16 | b.join().unwrap(); 17 | c.join().unwrap(); 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /boxes/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "boxes" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /boxes/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let c = Box::new([0u32; 10_000_000]); 3 | println!("{}", c.len()); 4 | } 5 | -------------------------------------------------------------------------------- /byte_sized/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "byte_sized" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /byte_sized/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut counter : i8 = 0; 3 | loop { 4 | println!("{}", counter); 5 | counter += 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /byte_sized_wrap/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "byte_sized_wrap" 3 | version = "0.1.0" 4 | authors = ["herbe"] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /byte_sized_wrap/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::num::Wrapping; 2 | 3 | fn main() { 4 | let mut counter = Wrapping(0i8); 5 | loop { 6 | println!("{}", counter); 7 | counter += Wrapping(1i8); 8 | } 9 | } -------------------------------------------------------------------------------- /const_loop/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_loop" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /const_loop/src/main.rs: -------------------------------------------------------------------------------- 1 | const fn fib(n: u128) -> u128 { 2 | let mut a = 1; 3 | let mut b = 1; 4 | for _ in 2..n { 5 | let tmp = a + b; 6 | a = b; 7 | b = tmp; 8 | } 9 | b 10 | } 11 | 12 | fn main() { 13 | for i in 0..5 { 14 | println!("Fib {} = {}", i, fib(i)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /const_loop_works/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "const_loop_works" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /const_loop_works/src/main.rs: -------------------------------------------------------------------------------- 1 | const fn fib(n: u128) -> u128 { 2 | let mut a = 1; 3 | let mut b = 1; 4 | let mut counter = 2; 5 | while counter < n { 6 | let tmp = a + b; 7 | a = b; 8 | b = tmp; 9 | counter += 1; 10 | } 11 | b 12 | } 13 | 14 | fn main() { 15 | for i in 0..5 { 16 | println!("Fib {} = {}", i, fib(i)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /double_or_nothing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "double_or_nothing" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /double_or_nothing/src/main.rs: -------------------------------------------------------------------------------- 1 | fn double_it(n: i32) -> i32 { 2 | n * 2 3 | } 4 | 5 | fn double_it(n: f32) -> f32 { 6 | n * 2.0 7 | } 8 | 9 | fn main() { 10 | println!("2 * 4 = {}", double_it(2)); 11 | } 12 | -------------------------------------------------------------------------------- /double_or_nothing_working/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "double_or_nothing_working" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /double_or_nothing_working/src/main.rs: -------------------------------------------------------------------------------- 1 | fn double_it(n: T) -> T //(1) 2 | where T: std::ops::Mul + From//(2) 3 | { 4 | n * 2.into()//(3) 5 | } 6 | 7 | fn main() { 8 | println!("2+2 = {}", double_it(2)); 9 | } 10 | -------------------------------------------------------------------------------- /gordian_knot/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gordian_knot" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /gordian_knot/src/main.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | struct Parser<'a> { 3 | body: String, 4 | subtext : &'a str, 5 | } 6 | 7 | fn main() { 8 | let mut document = Parser { 9 | body: "Hello".to_string(), 10 | subtext: "" 11 | }; 12 | document.subtext = &document.body; 13 | 14 | let b = document; 15 | println!("{:?}", b); 16 | } 17 | -------------------------------------------------------------------------------- /hello_bonjour/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_bonjour" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /hello_bonjour/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let hello = || println!("Hello World"); 3 | let hello = || println!("Bonjour le monde"); 4 | hello(); 5 | } 6 | -------------------------------------------------------------------------------- /hello_bonjour_const/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_bonjour_const" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /hello_bonjour_const/src/main.rs: -------------------------------------------------------------------------------- 1 | enum Language { English, French } 2 | 3 | const fn hello(language: Language) -> &'static str { 4 | match language { 5 | Language::English => "Hello World", 6 | Language::French => "Bonjour le monde", 7 | } 8 | } 9 | 10 | fn main() { 11 | println!("{}", hello(Language::English)); 12 | } 13 | -------------------------------------------------------------------------------- /hello_bonjour_static/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_bonjour_static" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [features] 7 | english = [] 8 | french = [] 9 | 10 | [dependencies] 11 | -------------------------------------------------------------------------------- /hello_bonjour_static/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | #[cfg(feature = "english")] 3 | let hello = || println!("Hello World"); 4 | #[cfg(feature = "french")] 5 | let hello = || println!("Bonjour le monde"); 6 | hello(); 7 | } 8 | -------------------------------------------------------------------------------- /linked_list/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "linked_list" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /linked_list/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::cell::RefCell; 2 | use std::rc::Rc; 3 | 4 | type Link = Option>>; 5 | 6 | #[derive(Debug)] 7 | struct Node { 8 | elem: i32, 9 | next: Link, 10 | } 11 | 12 | fn main() { 13 | let mut head = Some(Rc::new( 14 | RefCell::new(Node{ elem: 1, next: None }) 15 | )); 16 | head 17 | .as_mut() 18 | .unwrap() 19 | .borrow_mut() 20 | .next = Some(Rc::new(RefCell::new( 21 | Node{ elem: 2, next: head.clone() }) 22 | )); 23 | 24 | println!("{:?}", head); 25 | } 26 | -------------------------------------------------------------------------------- /misc/shadow_example.rs: -------------------------------------------------------------------------------- 1 | { 2 | let x = 123; //(1) 3 | { //(2) 4 | let x = x as f32; //(3) 5 | x *= 2.0; //(4) 6 | println!("x = {}", x); //(5) 7 | } //(6) 8 | println!("x = {}, x"); //(7) 9 | } -------------------------------------------------------------------------------- /morse_code/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "morse_code" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /morse_code/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | .. .. ..; 3 | } -------------------------------------------------------------------------------- /mutable_immutable/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mutable_immutable" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /mutable_immutable/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let life_the_universe = &mut 41; 3 | *life_the_universe += 1; 4 | println!("Life, the Universe and Everything: {}", life_the_universe); 5 | } 6 | -------------------------------------------------------------------------------- /out_of_order/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "out_of_order" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /out_of_order/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut floats = vec![3.1, 1.2, 4.5, 0.3]; 3 | floats.sort(); 4 | 5 | println!("{:#?}", floats); 6 | } -------------------------------------------------------------------------------- /quack/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "quack" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /quack/src/main.rs: -------------------------------------------------------------------------------- 1 | fn double_it(n: u64, _: i32) -> u64 { 2 | n * 2 3 | } 4 | 5 | fn main() { 6 | let one: i32 = 1; 7 | let n = double_it(one as _, 3); 8 | println!("{}", n); 9 | } 10 | -------------------------------------------------------------------------------- /reboot_universe/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "reboot_universe" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /reboot_universe/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | if 0.1 + 0.2 == 0.3 { 3 | println!("Arithmetic still works."); 4 | } else { 5 | println!("Please reboot the universe."); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /reverse_polarity/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "reverse_polarity" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /reverse_polarity/src/main.rs: -------------------------------------------------------------------------------- 1 | fn display_neutron_flow(polarity: isize) { 2 | println!( 3 | "Neutron Flow is {}", 4 | if polarity < 0 { "reversed"} else { "normal" } 5 | ); 6 | } 7 | 8 | fn main() { 9 | let polarity = 1; 10 | { 11 | let polarity = polarity - 2; 12 | display_neutron_flow(polarity); 13 | } 14 | display_neutron_flow(polarity); 15 | } 16 | -------------------------------------------------------------------------------- /sleepless/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sleepless" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | tokio = { version = "1.7", features = ["full"] } -------------------------------------------------------------------------------- /sleepless/src/main.rs: -------------------------------------------------------------------------------- 1 | use tokio::join; 2 | use std::time::Duration; 3 | 4 | async fn count_and_wait(n: u64) -> u64 { 5 | println!("Starting {}", n); 6 | std::thread::sleep(Duration::from_millis(n * 100)); 7 | println!("Returning {}", n); 8 | n 9 | } 10 | 11 | #[tokio::main] 12 | async fn main() -> Result<(), Box> { 13 | // Join runs multiple tasks concurrently and returns when they all 14 | // complete execution. 15 | join!(count_and_wait(1), count_and_wait(2), count_and_wait(3)); 16 | Ok(()) 17 | } 18 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("You probably meant to run one of the workspace members."); 3 | println!("Please enter the appropriate child directory and run it"); 4 | } 5 | -------------------------------------------------------------------------------- /standard_input/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "standard_input" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /standard_input/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn main() { 4 | println!("What is 3+2? Type your answer and press enter."); 5 | let mut input = String::new(); 6 | stdin() 7 | .read_line(&mut input) 8 | .expect("Unable to read standard input"); 9 | 10 | if input == "5" { 11 | println!("Correct!"); 12 | } else { 13 | println!("Incorrect!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /string_length/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "string_length" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /string_length/src/main.rs: -------------------------------------------------------------------------------- 1 | const HELLO_WORLD : &'static str = "Halló heimur"; 2 | 3 | fn main() { 4 | println!("{} is {} characters long.", 5 | HELLO_WORLD, 6 | HELLO_WORLD.len() 7 | ); 8 | } 9 | -------------------------------------------------------------------------------- /structure_sizing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "structure_sizing" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /structure_sizing/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::mem::size_of; 2 | 3 | struct VeryImportantMessage { 4 | _message_type: u8, 5 | _destination: u16 6 | } 7 | 8 | fn main() { 9 | println!( 10 | "VeryImportantMessage occupies {} bytes.", 11 | size_of::() 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /there_and_back/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "there_and_back" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /there_and_back/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | pub struct Degrees(pub f32); 4 | pub struct Radians(pub f32); 5 | 6 | impl Degrees { 7 | pub fn new(angle: f32) -> Self { 8 | Self(angle) 9 | } 10 | } 11 | 12 | impl From for Radians { 13 | fn from(item : Degrees) -> Self { 14 | Self(item.0 * PI / 180.0) 15 | } 16 | } 17 | 18 | fn main() { 19 | let one_eighty_degrees = Degrees::new(180.0); 20 | let one_eighty_radians : Radians = one_eighty_degrees.into(); 21 | println!("180 Degrees in Radians = {}", one_eighty_radians.0); 22 | } -------------------------------------------------------------------------------- /three_and_a_bit/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "three_and_a_bit" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /three_and_a_bit/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | const THREE_AND_A_BIT : f32 = 3.4028236; 3 | println!("{}", THREE_AND_A_BIT); 4 | } 5 | -------------------------------------------------------------------------------- /type_conversion/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "type_conversion" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /type_conversion/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x : u64 = 4_294_967_296; 3 | let y = x as u32; 4 | if x == y as u64 { 5 | println!("x equals y."); 6 | } else { 7 | println!("x does not equal y."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /vec_size/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vec_size" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /vec_size/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut my_vec = Vec::with_capacity(1); 3 | my_vec.push("Hello"); 4 | println!("{}", my_vec.capacity()); 5 | my_vec.push("World"); 6 | println!("{}", my_vec.capacity()); 7 | } 8 | -------------------------------------------------------------------------------- /waiting_for_godot/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "waiting_for_godot" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | tokio = { version = "1", features = ["full"] } 8 | -------------------------------------------------------------------------------- /waiting_for_godot/src/main.rs: -------------------------------------------------------------------------------- 1 | async fn hello() { 2 | println!("Hello, World!") 3 | } 4 | 5 | #[tokio::main] 6 | pub async fn main() -> Result<(), Box> { 7 | hello(); 8 | Ok(()) 9 | } -------------------------------------------------------------------------------- /x_marks_spot/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "x_marks_spot" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /x_marks_spot/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | if 'X' == 'Χ' { 3 | println!("It matches!"); 4 | } else { 5 | println!("It doesn't match."); 6 | } 7 | } 8 | --------------------------------------------------------------------------------