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!

Required Associated Types§

source

type Immutable: ?Sized + Message

The immutable counterpart of the type, or Self if the type has no immutable counterpart.

The implementation for NSString has itself (NSString) here, while NSMutableString instead has NSString.

source

type Mutable: ?Sized + Message

The mutable counterpart of the type, or Self if the type has no mutable counterpart.

The implementation for NSString has NSMutableString here, while NSMutableString has itself (NSMutableString).

Implementors§

source§

impl<P: ?Sized> CounterpartOrSelf for ProtocolObject<P>

source§

impl<T: ?Sized + ClassType> CounterpartOrSelf for T
where T::Mutability: MutabilityCounterpartOrSelf<T>,

§

type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable

§

type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable