Hacker News new | ask | show | jobs
by Waterluvian 2307 days ago
The function "consumes" the value. Its no longer valid in the function caller's scope.

Often the purpose is to consume the value and return a new kind of value. Maybe `validate_square` takes in `Shape` and returns `Option<Shape>`

If valid or invalid, we have consumed the shape so it cant be reused by accident and can't be used without handling the optional branches.

I'm new so maybe I'm off on this.

1 comments

In Rust, this is how “ownership” works. Once a variable is moved to a new scope, ownership moves with it, which means that it cannot be used in the current scope anymore.