Method Syntax - The Rust Programming Language
Methods are similar to functions: we declare them with the fn keyword and a name, they can have parameters and a return value, and they contain some code that’s run when the method is called from somewhere else. Unlike functions, methods are defined within the context of a struct (or an enum or a trait object, which we cover in Chapters 6 and 17, respectively), and their first parameter is always self, which represents the instance of the struct the method is being called on.
Methods - The Rust Programming Language Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Auto Light Rust Coal Navy Ayu The Rust Programming Language Methods Methods are similar to functions: We declare them with the fn keyword and a name, they can have parameters and a return value, and they contain some code that’s run when the method is called from somewhere else. Unlike functions, methods are defined within the context of a struct (or an enum or a trait object, which we cover in Chapter 6 an
Explore this link on the map →saved by
related reading
- Defining Shared Behavior with Traits - The Rust Programming Languagedoc.rust-lang.org
- An Example Program Using Structs - The Rust Programming Languagedoc.rust-lang.org
- A half-hour to learn Rustfasterthanli.me
- Defining and Instantiating Structs - The Rust Programming Languagedoc.rust-lang.org
- Defining an Enum - The Rust Programming Languagedoc.rust-lang.org
- The Slice Type - The Rust Programming Languagedoc.rust-lang.org
- What is Ownership? - The Rust Programming Languagedoc.rust-lang.org
- The match Control Flow Construct - The Rust Programming Languagedoc.rust-lang.org
- Generic Data Types - The Rust Programming Languagedoc.rust-lang.org
- Rust Language Cheat Sheetcheats.rs
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- Item 7: Use builders for complex types - Effective Rustlurklurk.org