rustlings Documentation

Crab: Small exercises to get you used to reading and writing Rust code!

63,857 stars Rust Rust 1 file ยท ~1,617 tokens #beginner-friendly#exercises#rust#rustlings
RAW Doc

File: README.md

[Rustlings](https://rustlings.rust-lang.org) ๐Ÿฆ€

Small exercises to get you used to reading and writing Rust code - Recommended in parallel to reading the official Rust book ๐Ÿ“š๏ธ

Visit the website for a demo, info about setup and more:

โžก๏ธ [rustlings.rust-lang.org](https://rustlings.rust-lang.org) โฌ…๏ธ


File: exercises/quizzes/README.md

Quizzes

After every couple of sections, there will be a quiz in this directory that'll test your knowledge on a bunch of sections at once.


File: exercises/23_conversions/README.md

Type conversions

Rust offers a multitude of ways to convert a value of a given type into another type.

The simplest form of type conversion is a type cast expression. It is denoted with the binary operator as. For instance, println!("{}", 1 + 1.0); would not compile, since 1 is an integer while 1.0 is a float. However, println!("{}", 1 as f32 + 1.0) should compile. The exercise conversions1 tries to cover this.

Rust also offers traits that facilitate type conversions upon implementation. These traits can be found under the convert module.
The traits are the following:

Furthermore, the std::str module offers a trait called FromStr which helps with converting strings into target types via the parse method on strings. If properly implemented for a given type Person, then let p: Person = "Mark,20".parse().unwrap() should both compile and run without panicking.

These should be the main ways within the standard library to convert data into your desired types.

Further information

These are not directly covered in the book, but the standard library has a great documentation for it.


File: exercises/22_clippy/README.md

Clippy

The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code.

If you used the installation script for Rustlings, Clippy should be already installed.
If not you can install it manually via rustup component add clippy.

Further information


File: exercises/21_macros/README.md

Macros

Rust's macro system is very powerful, but also kind of difficult to wrap your
head around. We're not going to teach you how to write your own fully-featured
macros. Instead, we'll show you how to use and create them.

If you'd like to learn more about writing your own macros, the
macrokata project has a similar style
of exercises to Rustlings, but is all about learning to write Macros.

Further information


File: exercises/20_threads/README.md

Threads

In most current operating systems, an executed program's code is run in a process, and the operating system manages multiple processes at once.
Within your program, you can also have independent parts that run simultaneously. The features that run these independent parts are called threads.

Further information


File: exercises/19_smart_pointers/README.md

Smart Pointers

In Rust, smart pointers are variables that contain an address in memory and reference some other data, but they also have additional metadata and capabilities.
Smart pointers in Rust often own the data they point to, while references only borrow data.

Further Information


File: exercises/18_iterators/README.md

Iterators

This section will teach you about Iterators.

Further information


File: exercises/17_tests/README.md

Tests

Going out of order from the book to cover tests -- many of the following exercises will ask you to make tests pass!

Further information


File: exercises/16_lifetimes/README.md

Lifetimes

Lifetimes tell the compiler how to check whether references live long
enough to be valid in any given situation. For example lifetimes say
"make sure parameter 'a' lives as long as parameter 'b' so that the return
value is valid".

They are only necessary on borrows, i.e. references,
since copied parameters or moves are owned in their scope and cannot
be referenced outside. Lifetimes mean that calling code of e.g. functions
can be checked to make sure their arguments are valid. Lifetimes are
restrictive of their callers.

If you'd like to learn more about lifetime annotations, the
lifetimekata project
has a similar style of exercises to Rustlings, but is all about
learning to write lifetime annotations.

Further information