Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new Rc pointer.
Rust
let value = Rc::[1](5);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using clone instead of new to create the Rc.
Using downgrade which is for Weak pointers.
✗ Incorrect
Use Rc::new to create a new reference-counted pointer.
2fill in blank
mediumComplete the code to clone an existing Rc pointer.
Rust
let rc2 = [1](&rc1); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Rc::new which creates a new pointer with new data.
Using Rc::downgrade which creates a Weak pointer.
✗ Incorrect
Use Rc::clone to create a new pointer to the same data, increasing the reference count.
3fill in blank
hardFix the error in the code to get the strong count of an Rc pointer.
Rust
let count = Rc::[1](&rc1); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using clone which copies the pointer.
Using downgrade which creates a Weak pointer.
✗ Incorrect
The method strong_count returns how many Rc pointers share ownership.
4fill in blank
hardFill both blanks to create an Rc pointer and clone it.
Rust
let rc1 = Rc::[1](10); let rc2 = Rc::[2](&rc1);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using downgrade instead of clone.
Using strong_count instead of clone.
✗ Incorrect
First create a new Rc pointer with new, then clone it with clone.
5fill in blank
hardFill all three blanks to create an Rc pointer, clone it, and get the strong count.
Rust
let rc1 = Rc::[1](20); let rc2 = Rc::[2](&rc1); let count = Rc::[3](&rc1);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using downgrade instead of clone or strong_count.
Mixing up the order of methods.
✗ Incorrect
Create a new Rc pointer with new, clone it with clone, and get the count with strong_count.