Rust Book Full Project Examples?

Is there any github where all the examples/projects in the rust book lie?

I want to see the full layout of all the code for the IO project and I can't find it anywhere.

If not, are there any repos with good, full code examples (with the cargo.toml and the full file layout for each project required to build from scratch)?

The source of the book can be found at https://github.com/rust-lang/book/tree/master/src

The code examples are directly embedded inside the markdown files For example https://github.com/rust-lang/book/blob/master/src/ch03-05-control-flow.md

If you want to run them yourself, you can just create a new project using cargo new and paste the code inside the main function.

Carol has been working on extracting the examples so that they’re easier to examine on their own, but it’s taking a while! There are a lot of them.

I'd love to take a look! :eyes:

I spotted an issue around this and running rustfmt on all the code sections for consistency (barring some edge cases where "incorrect" formatting is necessary for the learning point).

Currently messing around with sed and awk to see if I can help. I'll comment there if I get anything useful.

I have the work on a branch and I'm working on some scripts to make updating error messages and rustfmting easier; I was also waiting on some mdbook features I needed to be merged, released, and included in rust-lang/rust. That has now happened so I should be able to merge soon!

I also created a release artifact that contains just the listings so you don't have to go digging around the entire repo. Please check it out and see if that's what you're looking for and let me know if not!

4 Likes