From the course: First Look: Rust

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

How functions work

How functions work - Rust Tutorial

From the course: First Look: Rust

Start my 1-month free trial

How functions work

- [Narrator] A function is a block of organized, reusable code that is used to perform a single related action. Functions provide better modularity for your application and a high degree of code reusing. Let me just open up "hello_word.rs," the first Rust file we've written. We've already seen one of the most important functions in the language, the main function, which is the entry point of many programs. We have also seen the fn keyword, which allows you to declare new functions. Rust code uses snake case as the conventional style for function and variable names. In snake case, all letters are lowercase and underscores separate words. Function definitions in Rust start with "fn" and have a set of parentheses after the function name. The curly brackets tell the compiler where the function body begins and where it ends. Let's open up our command prompt and start a new binary project named "functions." You know how to do it. "Cargo new functions" followed by "bin." This creates the…

Contents