Rust Brain Teasers (Pragmatic Bookshelf)

PragmaticBookshelf
Level up your Rust programming skills with a series of brain teasers as you discover some of the unexpected Rust behaviors and challenge your brain.

Herbert Wolverson @herbert

Tammy Coron @Paradox927

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?

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.

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.

Are you ready to experience Rust like never before? Then sharpen your brain and get ready for a challenge!


Herbert Wolverson author of Hands-on Rust, has worked as a programmer and indie game developer since the late 1990s. He’s taught programming and IT skills at a variety of levels, contributes to multiple open source projects, and is active in the game development scene.


Don’t forget you can get 35% off with your Devtalk discount! Just use the coupon code “devtalk.com" at checkout :+1:

Latest Threads About This Book Top

hughdbrown
@herbert These are the links for asynchronous rust: Further Reading Asynchronous Programming in Rust https://rust-lang.github.io/asyn...
New
Red
An open discussion about this particular puzzle on asynchronous code, since I’m only learning and I may have overlooked something. 1.) A...
New
Red
The page number is absent for the “card” pages unfortunately, but it’s before page 70. println!("2 * 4 = {}", double_it(2)); should be ...
New
Red
@herbert 4th paragraph: “When a variable “drops” out of scope, it’s drop destructor is automatically called.” => “its”
New
Red
The author apparently contradicts himself, since in the discussion it becomes apparent that the program will be terminated after running ...
New
Red
I see mentions of the ‘IEE-754’ standard, but as far as I know, it’s the IEEE 754-2008 standard (the first paragraph got it right though)...
New
dylanmc
Title: Rust Brain Teasers, page 47 “Because of the extra steps required for heap read/write access—particularly with frequent allocation...
New
mikecargal
Rust Brain Teasers: println!("2 * 4 = {}, double_it(2)) (Puzzle 16) I know this is very pedantic (and “besides the point” of this puzzle...
New
mikecargal
Rust Brain Teasers: description (Puzzle15: To Infinity) On this line: fn fmt(&self, f: &mut fmt::Formatter<`_>) -> f...
New
andrewhalle
Title: Rust Brain Teasers: Type Conversion pg. 12 in the PDF clippy does lints for both narrowing a type which may be lossy (clippy::cas...
New

Most Active This Week Top

Most Active This Month Top

Most Active This Year Top

Most Active Last Three Years Top

Red
The page number is absent for the “card” pages unfortunately, but it’s before page 70. println!("2 * 4 = {}", double_it(2)); should be ...
New
hughdbrown
@herbert These are the links for asynchronous rust: Further Reading Asynchronous Programming in Rust https://rust-lang.github.io/asyn...
New
Red
I see mentions of the ‘IEE-754’ standard, but as far as I know, it’s the IEEE 754-2008 standard (the first paragraph got it right though)...
New
Red
The author apparently contradicts himself, since in the discussion it becomes apparent that the program will be terminated after running ...
New
Red
@herbert 4th paragraph: “When a variable “drops” out of scope, it’s drop destructor is automatically called.” => “its”
New
Red
An open discussion about this particular puzzle on asynchronous code, since I’m only learning and I may have overlooked something. 1.) A...
New

Most Active Over Three Years Top

PragmaticBookshelf
Level up your Rust programming skills with a series of brain teasers as you discover some of the unexpected Rust behaviors and challenge ...
New
andrewhalle
Title: Rust Brain Teasers: Type Conversion pg. 12 in the PDF clippy does lints for both narrowing a type which may be lossy (clippy::cas...
New
dylanmc
Title: Rust Brain Teasers, page 47 “Because of the extra steps required for heap read/write access—particularly with frequent allocation...
New
nappa85
The phrase Unicode string character by character can consume a lot more memory than you expected. The string love: ❤ is 7 charac...
New
ekzeb
pdf beta 1.0 title: How long is String p. 21 “Rust correctly deduces that there are a total of 10 gylphs” << glyphs
New
mikecargal
Please use the following format for the title of this thread (then simply delete/replace this text with the content for the thread): Tit...
New
mikecargal
Rust Brain Teasers: description (Puzzle15: To Infinity) On this line: fn fmt(&amp;self, f: &amp;mut fmt::Formatter&lt;`_&gt;) -&gt; f...
New
mikecargal
Rust Brain Teasers: println!("2 * 4 = {}, double_it(2)) (Puzzle 16) I know this is very pedantic (and “besides the point” of this puzzle...
New

Get money off!

The Pragmatic Bookshelf

35% off any eBook

Simply use coupon code "devtalk.com" at checkout. See full details here.