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, like UnsafeCell)?
  • 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, so a safe default is often InteriorMutable, or of you’re working with GUI code, MainThreadOnly.

§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§

Traits§

  • Retrieve the immutable/mutable counterpart class, and fall back to Self if not applicable.
  • Marker trait for classes whose hash and isEqual: methods are stable.
  • Marker trait for classes that can be allocated from any thread.
  • Marker trait for classes that may feasibly be used behind a mutable reference.
  • Marker trait for classes where Retained::clone / Id::clone is safe.
  • Marker trait for classes that are only available on the main thread.
  • 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.