0
0
Rustprogramming~10 mins

Rc pointer in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new Rc pointer.

Rust
let value = Rc::[1](5);
Drag options to blanks, or click blank then click option'
Anew
Bclone
Cstrong_count
Ddowngrade
Attempts:
3 left
💡 Hint
Common Mistakes
Using clone instead of new to create the Rc.
Using downgrade which is for Weak pointers.
2fill in blank
medium

Complete the code to clone an existing Rc pointer.

Rust
let rc2 = [1](&rc1);
Drag options to blanks, or click blank then click option'
ARc::clone
BRc::new
CRc::downgrade
DRc::strong_count
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.
3fill in blank
hard

Fix 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'
Aclone
Bdowngrade
Cstrong_count
Dnew
Attempts:
3 left
💡 Hint
Common Mistakes
Using clone which copies the pointer.
Using downgrade which creates a Weak pointer.
4fill in blank
hard

Fill 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'
Anew
Bclone
Cdowngrade
Dstrong_count
Attempts:
3 left
💡 Hint
Common Mistakes
Using downgrade instead of clone.
Using strong_count instead of clone.
5fill in blank
hard

Fill 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'
Anew
Bclone
Cstrong_count
Ddowngrade
Attempts:
3 left
💡 Hint
Common Mistakes
Using downgrade instead of clone or strong_count.
Mixing up the order of methods.