Are there any C++ primer style books to learn Rust from?

EDIT: After posting this, I found Programming Rust: Fast, Safe Systems Development. I am hesitant to use it now, however, as it is a bit outdated (2017, and Rust has a 2018 edition in which at least something surely changed). If someone could shed some light on this book, that would be great.


I just started trying to learn Rust, but, so far, it has been an incredibly frustrating experience due to the sub-par resources. Specifically, the resources (even the long-form book) tend to not cover essential details while simultaneously having a lot more text to slog through than they need to cover what they do cover. The latter problem may contribute to my perception of the former, as long text to slog through tends to reduce attention to detail so anything that is only briefly mentioned is liable to be missed.

When I learned C++ I originally had a similar experience with the online tutorials, so I did some research and found C++ Primer 5th edition to properly describe the language. That is, it rigorously covers every detail without leaving anything out, and it does so in an order such that you rarely, if ever, need to rely on something that isn't yet explained. In the few cases where it does need to do something like that, it explicitly says so, says where it is properly covered, and gives a simplified explanation to allow the reader to have an internal and precise mental model of what is going on, just one that doesn't cover everything that C++ can do (every program that one writes with that model is correct, but not all correct programs work with that model). Furthermore, it gives exercises after each section that are successfully designed to tease out the subtleties that come with such extreme detail, in order to make sure that the reader truly understands what is going on as opposed to just being able to usually write correct code and blindly throw words at search engines when something is wrong.

Some examples of the essential information that the long form leaves out are:

  • value/reference semantics when calling functions aren't mentioned at all in the function or variable sections of chapter 3
  • multiple files aren't anywhere as far as I can tell¹
  • str& vs std::io::String also isn't anywhere as far as I can tell¹
  • println!'s flushing behavior (I tried print! and was suprised when it didn't flush) isn't covered with pringln!
  • if statement comparisons with the std::io::String object isn't in the if statement tutorial, even after introducing the String type
  • Why doesn't String follow the snake case standard?

The failure of Rust's book to do what C++ Primer does leads to numerous issues. For example, when I wrote the fibbonacci example, I wanted it to loop until the user writes "quit," and then end the program. When I wrote if user_input == "quit", however, the condition always evaluated to false and CLion's Rust plugin complained about a syntax error. From CLion's syntax error, I was able to find out about str& and std::io::String and I at least have something to go on to research to fix the issue, but, with decent learning materials I wouldn't have to as even the temporary model to cover strings before classes (if this is even the right order for Rust) would always produce correct programs, or it would be made explicit that string comparisons are impossible until a particular chapter so I would simply wait until I got there.

So, I ask, are there any resources for learning Rust that have the strengths of C++ Primer, so I am not constantly frustrated from running into brick walls of stuff that the official long-form book just decided to leave unknown?

Thank you

1: "as far as I can tell," in this context, means that I don't remember reading anything with how far I got that either covered it or explicitly said that it would be covered later (even without a temporary mental model) and none of the section titles on the left of the online book seem relevant.

Writing good books on languages takes skill and time:

C++ was introduced to the world in 1985. The first edition of the Primer you mention was published four years later in 1989

The first stable version of Rust was 2015, 4.5 years ago.

We can expect what you want to be published about now...

Luckily the error messages and hints that come out of the compiler mean the need for such books is not so urgent.

Besides this is 2019, we have google, we have help, tutorials, advice everywhere over the net. Do people even write books like that anymore?

All values are moved into the function and references are values too. If a type happens to be Copy, then you can still access it after the move, because it has copy semantics. (Ch 4)

You may have to import the function with the use keyword. (Ch 7.4)

It's &str, not str& in Rust. There is no std::io::String in Rust, I think you mean std::string::String. The difference is explained in Ch 4.3

I don't think that this is relavant for begginers teaching material. It is better found in the std docs. Indeed, print's non-flushing behavior is documented right here

I'm not sure why this needs to be done. Ch 3.9 covers all the necessary operators. I don't think that it is the book's job to show you every possible combination of ways to do things. It should be fine to expect readers to play around with the language to see what is possible.

All types except for a few primitive ones follow PascalCase.

This is likely due to the input you are getting actually being "quit\n". If you have questions like these, feel free to post them here. There are a number of people who would be delighted to help!

I think that the book could do a better job of saying that something is coming up, but I'm not sure how helpful this could be without introducing bloat. Many thing are explained later in the book, but they are relavant early on, for example: Copy. If you have any question about Rust, feel free to ask them here. There are many people here who would love to answer all your questions.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.