Suggestion for The Book

I'm new to Rust, though a very experienced programmer (now retired, I wrote my first program on an IBM 1620 in assembly language in 1960!). Here's the issue:

In the References and Borrowing section, we are taught that creating a reference "borrows ownership". Subsequently, in "Thinking in Scopes", we are told that an inner scope is needed for the mutable borrow, because the println! creates an immutable borrow. Well, the println! looks like this:

println!("{}", x);

If you forget that println! is a macro, not a function, then you become confused, since passing the argument 'x' to a function does not constitute borrowing. The fact that the println! creates an immutable borrow only becomes apparent if you remember that println! is a macro and you look at how how it expands. I think the text ought to say this explicitly. Perhaps I've missed something (if so, please enlighten me), but I think the current presentation is not clear and explicit enough.

Don Allen

1 Like

This would probably be fine to do. I'd file a bug or make a PR for it. The key takeaway for a beginner should be that println! is a macro with slightly different rules; println! is an implicit borrow whereas everything is usually an explicit borrow.

And welcome here :slight_smile:

Thank you, how nice!

Rust looks very interesting. I've written a lot of C over the years, a bit of C++ (a language I detest), a fair amount of Haskell (in the last few years) and some Go in the last year.

I am still actively developing software, in C when performance is an issue, Tcl when it's not. A replacement for C that is less painful but provides comparable performance would be welcome and was the reason for my foray into Go and now my interest in Rust. A big issue is a need to talk to Sqlite. Gtk3 could also be a need, but not immediately.

Again, thanks for the greeting, and I will talk to you folks if I have anything I feel is worth discussing as I look further into Rust.

Don Allen

2 Likes