Module objc2::mutability
source · Expand description
Marker types for class mutability.
Every class must indicate which kind of mutability its instances use:
- Is the instance mutable or immutable?
- Does it use interior mutability (mutable behind
&self
, likeUnsafeCell
)? - Does it access global statics in such a way that the type is only safe to use from the main thread?
The answer to these facts influence the final capabilities the type has, as encoded in the traits in this module.
Concretely, you set ClassType::Mutability
to one of the types in this
module to indicate the properties of class you’re dealing with
(can be done inside extern_class!
and declare_class!
).
Note that precious little of Objective-C follows Rust’s usual shared xor unique ownership model, most often objects assume interior mutability.
SemVer
It is considered a major change to change the ClassType::Mutability
of
an object, though it can be done as a minor change in some cases to fix a
bug.
Structs
- Marker type for immutable classes.
- Marker type for immutable classes that have a mutable counterpart.
- Marker type for classes that use interior mutability.
- Marker type for classes that are only safe to use from the main thread.
- Marker type for mutable classes.
- Marker type for mutable classes that have a immutable counterpart.
- Marker type for root classes.
Traits
- Marker trait for classes that can be allocated from any thread.
- Marker trait for classes where
Id::clone
is safe. - Marker trait for classes that are only mutable through
&mut
. - Marker trait for classes where the
retain
selector is always safe. - Marker trait for the different types of mutability a class can have.