Structs and Resources
Move structs are plain typed data. Structs become resources when they carry the right abilities and are stored in global storage.
Simple structs
Section titled “Simple structs”module 0x2::example { struct Foo { x: u64, y: bool } struct Bar { foo: Foo }}By default, structs are module-private. If another module needs access, expose functions instead of assuming public field access.
The four abilities
Section titled “The four abilities”key: lets the struct live at the top level of global storage.store: lets the struct live inside another stored struct.drop: lets values be discarded when they go out of scope.copy: lets values be copied implicitly.
struct Message has copy, drop { text: String,}
struct Billboard has key { messages: vector<Message>,}Why resources matter
Section titled “Why resources matter”If a struct has key, it can be stored under an account or object address and becomes persistent on-chain state. That is the Move replacement for much of what Solidity developers mentally file under “contract storage”.
The migration habit to build early is: decide carefully which structs should not have copy, and which ones should be durable resources versus temporary values.