- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 104字
- 2021-07-02 23:07:19
Passing values around
Up to this point, we have kept everything within a single method. For small demonstrations (or for method testing), this is fine. However, for larger applications, passing values between methods is essential.
Rust has two main ways to pass information to other methods: by reference or by value. Passing by reference usually implies borrowing, which means that ownership is only temporarily given and can be used again after the function call. Passing by value implies either a permanent ownership change, which means that the caller of a function can no longer access the value, or it might imply copying the data.