zerocopy

Derive Macro Immutable

#[derive(Immutable)]
Expand description

Analyzes whether a type is Immutable.

This derive analyzes, at compile time, whether the annotated type satisfies the safety conditions of Immutable and implements Immutable if it is sound to do so. This derive can be applied to structs, enums, and unions; e.g.:

#[derive(Immutable)]
struct MyStruct {
    ...
}

#[derive(Immutable)]
enum MyEnum {
    ...
}

#[derive(Immutable)]
union MyUnion {
    ...
}

§Analysis

This section describes, roughly, the analysis performed by this derive to determine whether it is sound to implement Immutable for a given type. Unless you are modifying the implementation of this derive, you don’t need to read this section.

If a type has the following properties, then this derive can implement Immutable for that type:

  • All fields must be Immutable.

This analysis is subject to change. Unsafe code may only rely on the documented safety conditions of Immutable, and must not rely on the implementation details of this derive.