Skip to content

Commit fecb2e7

Browse files
committed
Add some more documentation to Owned and Retained
1 parent f52bc56 commit fecb2e7

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/rc/owned.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ use crate::runtime::{self, Object};
1616
///
1717
/// This is guaranteed to have the same size as the underlying pointer.
1818
///
19+
/// # Cloning and [`Retained`]
20+
///
21+
/// This does not implement [`Clone`], but [`Retained`] has a [`From`]
22+
/// implementation to convert from this, so you can easily reliquish ownership
23+
/// and work with a normal [`Retained`] pointer.
24+
///
25+
/// ```no_run
26+
/// let obj: Owned<T> = ...;
27+
/// let retained: Retained<T> = obj.into();
28+
/// let cloned: Retained<T> = retained.clone();
29+
/// ```
30+
///
1931
/// TODO: Explain similarities to [`Box`].
2032
///
2133
/// TODO: Explain this vs. [`Retained`]
@@ -43,7 +55,8 @@ impl<T> Owned<T> {
4355
/// else, usually Objective-C methods like `init`, `alloc`, `new`, or
4456
/// `copy`).
4557
///
46-
/// Additionally, there must be no other pointers to the same object.
58+
/// Additionally, there must be no other pointers or references to the same
59+
/// object, and the given reference must not be used afterwards.
4760
///
4861
/// # Example
4962
///
@@ -55,6 +68,8 @@ impl<T> Owned<T> {
5568
/// ```
5669
///
5770
/// TODO: Something about there not being other references.
71+
// Note: The fact that we take a `&mut` here is more of a lint; the lifetime
72+
// information is lost, so whatever produced the reference can still be
5873
#[inline]
5974
pub unsafe fn new(obj: &mut T) -> Self {
6075
Self {

src/rc/retained.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ use core::ptr::NonNull;
99
use super::Owned;
1010
use crate::runtime::{self, Object};
1111

12-
/// A smart pointer that strongly references an object, ensuring it won't be
12+
/// An smart pointer that strongly references an object, ensuring it won't be
1313
/// deallocated.
1414
///
15+
/// This doesn't own the object, so it is not safe to obtain a mutable
16+
/// reference from this. For that, see [`Owned`].
17+
///
1518
/// This is guaranteed to have the same size as the underlying pointer.
1619
///
1720
/// TODO: Something about the fact that we haven't made the methods associated

0 commit comments

Comments
 (0)