Skip to content

Commit f6283d2

Browse files
committed
Improve mutability docs
1 parent 342675f commit f6283d2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

crates/objc2/src/mutability.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ pub struct Mutable {
104104
/// The mutable counterpart must be specified as the type parameter `MS` to
105105
/// allow `NSCopying` and `NSMutableCopying` to return the correct type.
106106
///
107+
/// Functionality that is provided with this:
108+
/// - [`IsIdCloneable`].
109+
/// - [`IsAllocableAnyThread`].
110+
/// - You are allowed to hand out pointers / references to an instance's
111+
/// internal data, since you know such data will never be mutated.
112+
///
107113
///
108114
/// # Example
109115
///
@@ -256,7 +262,11 @@ impl<IS: ?Sized> Mutability for MutableWithImmutableSuperclass<IS> {}
256262
impl Mutability for InteriorMutable {}
257263
impl Mutability for MainThreadOnly {}
258264

259-
/// Marker trait for classes where [`Id::clone`][clone-id] is safe.
265+
/// Marker trait for classes where [`Id::clone`] is safe.
266+
///
267+
/// Since the `Foundation` collection types (`NSArray<T>`,
268+
/// `NSDictionary<K, V>`, ...) act as if they store [`Id`]s, this also makes
269+
/// certain functionality on those types possible.
260270
///
261271
/// This is implemented for classes whose [`ClassType::Mutability`] is one of:
262272
/// - [`Root`].
@@ -265,19 +275,24 @@ impl Mutability for MainThreadOnly {}
265275
/// - [`InteriorMutable`].
266276
/// - [`MainThreadOnly`].
267277
///
268-
/// [clone-id]: crate::rc::Id#impl-Clone-for-Id<T>
278+
/// [`Id`]: crate::rc::Id
279+
/// [`Id::clone`]: crate::rc::Id#impl-Clone-for-Id<T>
269280
pub trait IsIdCloneable: ClassType {}
270281
impl<T: ?Sized + ClassType> IsIdCloneable for T where T::Mutability: private::MutabilityIsIdCloneable
271282
{}
272283

273-
/// Marker trait for classes where the [`retain`] selector is always safe.
284+
/// Marker trait for classes where the `retain` selector is always safe.
285+
///
286+
/// [`Id::clone`] takes `&Id<T>`, while [`ClassType::retain`] only takes `&T`;
287+
/// the difference between these two is that in the former case, you know that
288+
/// there are no live mutable subclasses.
274289
///
275290
/// This is implemented for classes whose [`ClassType::Mutability`] is one of:
276291
/// - [`Immutable`].
277292
/// - [`InteriorMutable`].
278293
/// - [`MainThreadOnly`].
279294
///
280-
/// [`retain`]: ClassType::retain
295+
/// [`Id::clone`]: crate::rc::Id#impl-Clone-for-Id<T>
281296
pub trait IsRetainable: IsIdCloneable {}
282297
impl<T: ?Sized + ClassType> IsRetainable for T where T::Mutability: private::MutabilityIsRetainable {}
283298

0 commit comments

Comments
 (0)