AgentSkillsCN

cairo-storage-vecs

当请求涉及在 Cairo 中重构矩形面积计算,将其转化为结构体,并引入 `Into`/`TryInto` 转换时,讲解 Cairo 示例程序的用法——尤其适合参考第 5.2 章的结构体示例,或寻求基于结构体的重构方案。

SKILL.md
--- frontmatter
name: cairo-storage-vecs
description: Explain Starknet storage vectors with VecTrait and MutableVecTrait, element addressing, and operations; use when a request involves Vec-based storage in Cairo contracts.

Cairo Storage Vecs

Overview

Explain how storage vectors are modeled and accessed in Cairo smart contracts.

Quick Use

  • Read references/storage-vecs.md before answering.
  • Use Vec<T> only inside the storage struct.
  • Use len, get, at, append, and pop from the trait APIs.

Response Checklist

  • Mention that the length is stored at the base slot.
  • Explain element slot derivation from the base address and index.
  • Note that Vec types are storage-only and cannot be instantiated as normal variables.

Example Requests

  • "How do I append to a storage Vec?"
  • "How is the element address computed for a storage Vec?"
  • "Why can't I create Vec in a function?"