Module stabby::compiler_version

source ·
Expand description

Provides ZSTs that only implement IStable when built with their corresponding version of the compiler.

This allow the StableLike<T, CompilerVersion<Layout>> pattern.

CompilerVersion_MAJ_MIN_PATCH<Layout> will only impl IStable as if it was Layout, but only if compiled with the specified version of the compiler, providing you with a compile-time proof that you are using the expected compiler version.

Note that it is EXTREMELY memory-unsafe to lie about Layout if any type that contains this is used in a #[repr(stabby)] enum, since CompilerVersion<Layout> is ALWAYS a ZST, and non-() layouts should only be used in combination with StableLike<T, Layout>.

You can also add a compiler_version: CompilerVersion_VERSION<()> marker field in your structs to ensure that they are marked as stable only if compiled with the appropriate compiler version, however since the rest of the fields of the struct need to bi ABI-stable for IStable to be implemented, I think the applications are few and far between.

Structs§