@@ -29,31 +29,33 @@ unsafe {
29
29
30
30
The utilities of the ` rc ` module provide ARC-like semantics for working with
31
31
Objective-C's reference counted objects in Rust.
32
- A ` StrongPtr ` retains an object and releases the object when dropped.
33
- A ` WeakPtr ` will not retain the object, but can be upgraded to a ` StrongPtr `
34
- and safely fails if the object has been deallocated.
32
+
33
+ An ` Id ` retains an object and releases the object when dropped.
34
+ A ` WeakId ` will not retain the object, but can be upgraded to an ` Id ` and
35
+ safely fails if the object has been deallocated.
35
36
36
37
``` rust , no_run
37
38
use objc2 :: {class, msg_send};
38
- use objc2 :: rc :: {autoreleasepool, StrongPtr };
39
+ use objc2 :: rc :: {autoreleasepool, Id , Shared , WeakId };
40
+ use objc2 :: runtime :: Object ;
39
41
40
- // StrongPtr will release the object when dropped
41
- let obj = unsafe {
42
- StrongPtr :: new (msg_send! [class! (NSObject ), new ])
42
+ // Id will release the object when dropped
43
+ let obj : Id < Object , Shared > = unsafe {
44
+ Id :: new (msg_send! [class! (NSObject ), new ])
43
45
};
44
46
45
47
// Cloning retains the object an additional time
46
48
let cloned = obj . clone ();
47
- autoreleasepool (| _ | {
48
- // Autorelease consumes the StrongPtr , but won't
49
+ autoreleasepool (| pool | {
50
+ // Autorelease consumes the Id , but won't
49
51
// actually release until the end of an autoreleasepool
50
- cloned . autorelease ();
52
+ let obj_ref : & Object = cloned . autorelease (pool );
51
53
});
52
54
53
55
// Weak references won't retain the object
54
- let weak = obj . weak ( );
56
+ let weak = WeakId :: new ( & obj );
55
57
drop (obj );
56
- assert! (weak . load (). is_null ());
58
+ assert! (weak . load (). is_none ());
57
59
```
58
60
59
61
## Declaring classes
0 commit comments