A trait that allows for custom destruction behavior of a type. In Cairo, values must be explicitly handled - they cannot be silently dropped. Types can only go out of scope in two ways:Documentation Index
Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
Use this file to discover all available pages before exploring further.
- Implement
Drop- for types that can be discarded trivially - Implement
Destruct- for types that need cleanup when destroyed. Typically, any type that contains aFelt252Dictmust implementDestruct, as theFelt252Dictneeds to be “squashed” when going out of scope to ensure a program is sound.
Destruct does not need to be implemented manually. It can be derived from the
Drop and Destruct implementations of the type’s fields.
Signature
Examples
Here’s a simple type that wraps aFelt252Dict and needs to be destructed: