© Carlo Milanesi 2018
Carlo MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-3468-6_9

9. Defining Functions

Carlo Milanesi1 
(1)
Bergamo, Italy
 
In this chapter you will learn:
  • How to define your own procedures (better known as “functions”) and how to invoke them

  • When and how you can have several functions with the same name

  • How to pass arguments to a function, by-value or by-reference

  • How to return simple and composite values from a function

  • How to exit prematurely from a function

  • How references to objects can be manipulated

Defining and Invoking a Function

If it happens that you write the same code several times, you can encapsulate that code in a block, and then give that block a name. In this way you define a “function”. Then you can execute ...

Get Beginning Rust: From Novice to Professional 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.