Trait objc2::mutability::CounterpartOrSelf
source · pub unsafe trait CounterpartOrSelf: Sealed {
type Immutable: ?Sized + Message;
type Mutable: ?Sized + Message;
}
Expand description
Retrieve the immutable/mutable counterpart class, and fall back to Self
if not applicable.
This is used for describing the return type of NSCopying
and
NSMutableCopying
, since due to Rust trait limitations, those two can’t
have associated types themselves (since we want to use them in
ProtocolObject<dyn NSCopying>
).
§Usage notes
You may not rely on this being implemented entirely correctly for protocol objects, since we have less type-information available there.
In particular, the immutable counterpart of a mutable object converted to
ProtocolObject<dyn AProtocol>
may not itself implement the protocol, and
invalidly assuming it does is unsound.
All of this is to say: Do not use this trait in isolation, either require
NSCopying
or ClassType
along with it.
§Safety
This is a sealed trait, and should not need to be implemented. Open an issue if you know a use-case where this restrition should be lifted!