File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 21
21
//! [pull requests]: https://github.com/madsmtm/objc2/pulls
22
22
//! [`Message`]: crate::Message
23
23
//! [`msg_send!`]: crate::msg_send
24
+ //!
25
+ //!
26
+ //! # Use of `Deref`
27
+ //!
28
+ //! `objc2::foundation` uses the [`Deref`] trait in a bit special way: All
29
+ //! objects deref to their superclasses. For example, `NSMutableArray` derefs
30
+ //! to `NSArray`, which in turn derefs to `NSObject`.
31
+ //!
32
+ //! Note that this is explicitly recommended against in [the
33
+ //! documentation][`Deref`] and [the Rust Design patterns
34
+ //! book][anti-pattern-deref] (see those links for details).
35
+ //!
36
+ //! Due to Objective-C objects only ever being accessible behind pointers in
37
+ //! the first place, the problems stated there are less severe, and having the
38
+ //! implementation just means that everything is much nicer when you actually
39
+ //! want to use the objects!
40
+ //!
41
+ //! All objects also implement [`AsRef`] and [`AsMut`] to their superclass,
42
+ //! and can be used in [`Id::into_superclass`], so if you favour explicit
43
+ //! conversion, that is a possibility too.
44
+ //!
45
+ //! [`Deref`]: std::ops::Deref
46
+ //! [`ClassType`]: crate::ClassType
47
+ //! [anti-pattern-deref]: https://rust-unofficial.github.io/patterns/anti_patterns/deref.html
48
+ //! [`Id::into_superclass`]: crate::rc::Id::into_superclass
24
49
25
50
// TODO: Remove these
26
51
#![ allow( missing_docs) ]
You can’t perform that action at this time.
0 commit comments