Search⌘ K

Hello Method Calls!

Explore how to define and use methods in Rust programming. Learn the benefits of method calls over functions, such as name reuse and convenience, by practicing with common types like strings and integers.

We'll cover the following...

In Ownership and References, we’ve learned three fundamental concepts in Rust:

  • How to create our own data types using struct

  • How ownership and moving works

  • How to use references and mutable references

So far, we’ve demonstrated these concepts using functions. We pass ownership of a value from one function to another. Or we borrow a reference and pass that reference into a function.

There’s another concept in Rust that is very close to functions, called methods. We’re going to introduce methods now. We’ll see that they can sometimes be easier to use than functions. ...