Skip to main content

ImmutableObject

Trait ImmutableObject 

Source
pub unsafe trait ImmutableObject: ObjectCore { }
Expand description

An object type whose shared instances are never mutated, so ObjectArc<T> is Send + Sync when T’s fields are.

Implement it with the immutable option of rs_object or #[object(immutable)] on derive(Object), which reject writable fields.

§Safety

No code may mutate an instance while it is shared: changes go through copy-on-write, in place only on a uniquely held instance (one strong reference, no weak ones). This holds for every type not registered as mutable (_type_mutable), in any language. Every subclass must also be immutable while shared, with thread-safe fields; the derives reject a subtype that is not immutable at compile time. A hand-written impl must also set ObjectCore::TYPE_IMMUTABLE and keep every subtype immutable.

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.

Implementors§