O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Takeaways and tasks

Here are the key points from this section:

  • The syntax for generic types is <T>, where T can be of any valid Rust type.
  • In every block where it is used, it needs to be declared before it can be used. For instance, when declaring a function, <T> is declared just before the argument list.
  • The generic type, Option, in the standard library is used to represent any value that might be nothing.
  • The generic type, Result, is used to represent operations that may or may not succeed.

Here are a couple of tasks for you:

  1. Take a look at the collection types, documented in https://doc.rust-lang.org/stable/std/collections/.
  2. Use HashMap for any key-value type pairs you choose.
  3. Use BTreeMap for any key-value type pairs.
  4. Take a look at ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required