Skip to main content

Module deref

Module deref 

Source
Available on docsrs only.
Expand description

ยงUse of Deref

Framework crates uses the Deref trait in a bit special way: All objects deref to their superclasses. For example, NSMutableArray derefs to NSArray, which in turn derefs to NSObject.

Note that this is explicitly recommended against in the documentation and the Rust Design patterns book (see those links for details).

Due to Objective-C objects only ever being accessible behind pointers in the first place, the problems stated there are less severe, and having the implementation just means that everything is much nicer when you actually want to use the objects!

All objects also implement AsRef to their superclass, and can be used in Retained::into_super, so if you favour explicit conversion, that is a possibility too.