File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 5
5
use std:: rc:: { Rc , Weak } ;
6
6
use std:: ptr;
7
7
8
- /// Taken from the `Weak::as_raw ` doctest.
8
+ /// Taken from the `Weak::as_ptr ` doctest.
9
9
fn main ( ) {
10
10
let strong = Rc :: new ( Box :: new ( 42 ) ) ;
11
11
let weak = Rc :: downgrade ( & strong) ;
12
12
// Both point to the same object
13
- assert ! ( ptr:: eq( & * strong, Weak :: as_raw ( & weak) ) ) ;
13
+ assert ! ( ptr:: eq( & * strong, Weak :: as_ptr ( & weak) ) ) ;
14
14
// The strong here keeps it alive, so we can still access the object.
15
- assert_eq ! ( 42 , * * unsafe { & * Weak :: as_raw ( & weak) } ) ;
15
+ assert_eq ! ( 42 , * * unsafe { & * Weak :: as_ptr ( & weak) } ) ;
16
16
17
17
drop ( strong) ;
18
18
// But not any more. We can do Weak::as_raw(&weak), but accessing the pointer would lead to
19
19
// undefined behaviour.
20
- assert_eq ! ( 42 , * * unsafe { & * Weak :: as_raw ( & weak) } ) ; //~ ERROR dereferenced after this allocation got freed
20
+ assert_eq ! ( 42 , * * unsafe { & * Weak :: as_ptr ( & weak) } ) ; //~ ERROR dereferenced after this allocation got freed
21
21
}
You can’t perform that action at this time.
0 commit comments