Reference-counted pointers, Rc<T>
, are a type of smart pointer in Rust that allow multiple ownership of the same data. This means you can have multiple references to a value, and the value will only be dropped when the last reference is out of scope. This is particularly useful in scenarios where you want to share data between multiple parts of your program without needing to copy it.
In this challenge, you'll use Rc<T>
to share data between functions.
Implement the functions use_shared_data
and share_data_to_other_functions
to work with Rc<T>
.
use_shared_data
:
Rc<Vec<T>>
as argument.println!
.share_data_to_other_functions
:
If you're stuck, here are some hints to help you solve the challenge:
Rc::new
to wrap your vector in an Rc
smart pointer.Rc::clone
to create new references to the shared data.use_shared_data
, make sure to use T: Display
to allow printing elements with {}
formatting.