一键导入
rust-trait-object-layout
Rust trait object layout — DST fat pointers, vtable placement, generic last-field coercion surprise.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Rust trait object layout — DST fat pointers, vtable placement, generic last-field coercion surprise.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Canonical b00t reviewer capability — adversarial multi-framework code/datum review. Shared across all harnesses (Claude Code, opencode, Hermes, b00t-cli). Loaded via: b00t learn reviewer, or by harness-specific role supplements.
Remove AI-generated artifacts from code. Three-phase certainty-graded cleanup. Use after any AI implementation session or before PR creation.
8-phase agile workflow — strategy→ideate→brainstorm→plan→work→review→compound→pulse. State machine with FOL-guarded transitions, gh-issues backlog, executable just harness. Inspired by everyinc/compound-engineering-plugin.
Australian crypto tax treatment per ATO guidance QC 53725. Crypto assets are CGT assets under ITAA 1997 s 108-5. Each disposal triggers CGT event A1. Covers personal-use exception, trading stock test, and the 50% CGT discount.
Australian R&D Tax Incentive (RDTI) — ITAA 1997 Division 355. Covers eligibility criteria for core and supporting R&D activities, registration with AusIndustry/IP Australia, expenditure categories, offset rates, and the company size threshold test.
Evidence graph construction for tax audit trails. Each Satisfies check emits EvidenceNode structs with Blake3 content hashes. Evidence chains are tamper-evident and link legislative citations to factual findings.
| name | rust-trait-object-layout |
| type | skill |
| hint | Rust trait object layout, DST coercions, vtable fat-pointer internals, and the generic field unsized coercion surprise |
| version | 1.0.0 |
| tags | ["rust","advanced","trait-object","dst","vtable","coercion","transferable"] |
| tier | ch0nky |
| complexity | 7 |
| description | Rust trait object layout — DST fat pointers, vtable placement, generic last-field coercion surprise. |
Rust trait object layout differs critically from C++. In Rust, dyn Trait is a dynamically sized type whose layout is the underlying value. &dyn Trait is a fat pointer: (ptr_to_value, ptr_to_vtable). Box<dyn Trait> is an owned fat pointer with vtable via CoerceUnsized magic. The vtable is never embedded in the struct (unlike C++ where every object pays the cost) — it lives in the fat reference or Box.
The surprising coercion: generic last-field unsized coercion. If a struct has a generic as its LAST field, you can coerce &Struct<ConcreteType> to &Struct<dyn Trait>. Example: struct Adapter<R: ?Sized> { buf: Vec<u8>, inner: R } — let r: &Adapter<dyn Read> = &a; is legal because inner is the last field. This only works with a single generic — you cannot coerce two trait params. And Box/Rc do not support inline generic coercion through references: let r: &Box<dyn Read> = &b; is illegal, while let r: Box<dyn Read> = b; (ownership transfer) is legal.
Why this matters in b00t: DatumStore trait uses Box<dyn DatumStore> extensively. When wrapping adapters (e.g., CachingStore<HashMapStore>), the last-field coercion means &CachingStore<dyn DatumStore> is legal — useful for zero-cost adapter stacks. The Chalk Interner pattern relies on this layout guarantee.
Load this skill when working with Rust trait objects, DST coercions, vtable internals, or the DatumStore adapter stack in b00t. It is a prerequisite for datum-macro.
(data_ptr, vtable_ptr) for &dyn Trait and Box<dyn Trait>.&Struct<dyn Trait> for zero-cost adapter stacks; use Box<dyn Trait> for owned trait objects.&Box<dyn Trait> is not legal — use Box<dyn Trait> directly for ownership transfer.