Summary

  • The main we’ve seen so far is one example of a function.

  • We can define multiple other functions.

  • We can call functions similar to how we call macros (for example, println!).

  • Functions may take parameters, which are passed in from the caller.

  • Function parameters can be used as variables inside the body of a function.

  • Functions may return results of different types.

  • By default, functions return the unit () type.

  • A function body is a block, and may end with an expression, which will be its result value.

  • Function parameters are scoped to the function body.

  • Blocks create scopes for variables defined inside of them.

  • main is a normal function, but has some special rules:

    • It cannot take any parameters.

    • It can only have some special result types.

Get hands-on with 1200+ tech skills courses.