Implementing ClassType in declare_class! is unsafe because we need the user to uphold a few safety guarantees, and that was just the most convenient place to put the unsafe keyword.
Any invariants that the superclass ClassType::Super may have must be upheld.
ClassType::Mutability must be correct.
Drop must be implemented correctly.
We should work on ways to make fulfilling these unsafe requirements more granular.
One possibility for requirement 2 would be to migrate from an associated type Mutability to a constant, that you must initialize with unsafe if you need certain features:
Hmm, just realized that the proposed idea won't work, since you could do const MUTABILITY: Mutability = NSView::MUTABILITY;, and thereby bypass the unsafe.
Implementing
ClassType
indeclare_class!
isunsafe
because we need the user to uphold a few safety guarantees, and that was just the most convenient place to put theunsafe
keyword.After https://github.com/madsmtm/objc2/pull/521 though, the only safety guarantees that the user needs to uphold are:
ClassType::Super
may have must be upheld.ClassType::Mutability
must be correct.Drop
must be implemented correctly.We should work on ways to make fulfilling these
unsafe
requirements more granular.One possibility for requirement 2 would be to migrate from an associated type
Mutability
to a constant, that you must initialize withunsafe
if you need certain features: