© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
C. MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-7208-4_10

10. Defining Generic Functions and Types

Carlo Milanesi1  
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • How to write a single function definition, whose invocations can efficiently handle different data types

  • How to use type inference to avoid the need to specify the types used by generic functions

  • How to write a single struct, tuple-struct, or enum type, whose instances can efficiently contain different data types

  • How to use two important standard generic enums, Option and Result, to represent optional data or fallible functions results

  • How some standard functions ease the handling of ...

Get Beginning Rust: Get Started with Rust 2021 Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.