pub trait ComponentMutability: Seal + 'static {
const MUTABLE: bool;
}
Expand description
The mutability option for a Component
. This can either be:
This is controlled through either Component::Mutability
or #[component(immutable)]
when using the derive macro.
Immutable components are guaranteed to never have an exclusive reference,
&mut ...
, created while inserted onto an entity.
In all other ways, they are identical to mutable components.
This restriction allows hooks to observe all changes made to an immutable
component, effectively turning the OnInsert
and OnReplace
hooks into a
OnMutate
hook.
This is not practical for mutable components, as the runtime cost of invoking
a hook for every exclusive reference created would be far too high.
§Examples
#[derive(Component)]
#[component(immutable)]
struct ImmutableFoo;
Required Associated Constants§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.