use std::vector;fun vector_example() { let mut v = vector::empty<u64>(); vector::push_back(&mut v, 10); vector::push_back(&mut v, 20); let first = vector::borrow(&v, 0); // &10}
// Copy: can be copiedstruct Point has copy { x: u64, y: u64}// Drop: can be discardedstruct Data has drop { value: u64}// Store: can be stored in global storagestruct Item has store { id: u64}// Key: can be used as a key in global storagestruct Resource has key { id: UID}
Here’s a complete module showcasing basic concepts:
module my_package::counter { use sui::object::{Self, UID}; use sui::tx_context::TxContext; /// Counter object struct Counter has key { id: UID, value: u64 } /// Create a new counter public fun create(ctx: &mut TxContext): Counter { Counter { id: object::new(ctx), value: 0 } } /// Increment counter public fun increment(counter: &mut Counter) { counter.value = counter.value + 1; } /// Get current value public fun value(counter: &Counter): u64 { counter.value }}