rust-type-erasurelisted
Install: claude install-skill po4yka/rust-skills
# Rust type erasure
## Purpose
Decide how to hold values whose types the code does not name, and stop before you erase more
than you must. The one sentence not to get wrong: **`Any` keys nothing that borrows**, because
`impl<T: 'static + ?Sized> Any for T` is the only impl, and the error for that bound lands on
your caller, not on your map.
This skill owns the design of a type-keyed store, not the taste question of whether to erase at
all. `rust-discipline` owns that. Every error text and observed output below comes from rustc
1.97.0, edition 2024, on aarch64-apple-darwin, with Miri 0.1.0 on nightly.
## Route the symptom to a section
| Symptom or task | Section |
| --- | --- |
| `error[E0597]: ... argument requires that s is borrowed for 'static`, or `error: lifetime may not live long enough ... requires that 'a must outlive 'static` | [`Any` is bound to `'static`](#any-is-bound-to-static) |
| You reached for `type_name` because `TypeId::of` refused | [`type_name` is not a type key](#type_name-is-not-a-type-key) |
| Choosing between an enum, a `dyn Any` map, and something exotic | [The ladder](#the-ladder) |
| You must store a `Cow<'a, str>`, a `&'a [u8]`, or any borrow, keyed by type | [Rung 3](#rung-3-an-open-set-of-borrowed-values) |
| `error[E0271]: type mismatch resolving <P<'a> as Element<'a>>::Owner == Tag` | [The bijection is the collision proof](#the-bijection-is-the-collision-proof) |
| `error: incompatible lifetime on type` on an `Owner` or `Element` impl | [T