Version: 1.1.0
Explicit destruction
Some values must be ended on purpose. Mojo calls these explicit-destroy, or linear, types. Forgetting the call is a compile error.
Essentials
- The type opts in by defining an explicit destructor and suppressing the automatic one.
- The call site uses the destruction method the type provides.
- Every path, including errors, must destroy the value.
- This pattern fits locks, frames, and other resources with a required epilogue.
Example
fn finish(owned token: Token):
token.discard()
Keep in mind
Use this sparingly. Automatic destruction is the right default for ordinary data.