Trait Immutable

unsafe trait Immutable

Types which are free from interior mutability.

T: Immutable indicates that T does not permit interior mutation, except by ownership or an exclusive (&mut) borrow.

Implementation

Do not implement this trait yourself! Instead, use #[derive(Immutable)] (requires the derive Cargo feature); e.g.:

# use zerocopy_derive::Immutable;
#[derive(Immutable)]
struct MyStruct {
# /*
    ...
# */
}

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

#[derive(Immutable)]
union MyUnion {
#   variant: u8,
# /*
    ...
# */
}

This derive performs a sophisticated, compile-time safety analysis to determine whether a type is Immutable.

Safety

Unsafe code outside of this crate must not make any assumptions about T based on T: Immutable. We reserve the right to relax the requirements for Immutable in the future, and if unsafe code outside of this crate makes assumptions based on T: Immutable, future relaxations may cause that code to become unsound.

Implementors