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.use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for iter in data.iter() { println!("{}", iter); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let data = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&data)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ // 1. Loop over each item in the vector and print it using `println!` let _ = data.iter().for_each(|item| println!("{}", item));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let vec = Rc::new(items); take_item(Rc::clone(&vec)); take_item(Rc::clone(&vec)); take_item(Rc::clone(&vec));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>) where T: Display{ // 1. Loop over each item in the vector and print it using `println!` data.iter() .for_each(|a| println!("{}", a));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc = Rc::new(items); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: std::fmt::Display{ // 1. Loop over each item in the vector and print it using `println!` data.iter().for_each(|n| println!("{}", n));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc_data = Rc::new(items); take_item(Rc::clone(&rc_data)); take_item(Rc::clone(&rc_data)); take_item(Rc::clone(&rc_data));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>) where T: std::fmt::Display{ // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc_items = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&rc_items)) }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T>(data: Rc<Vec<T>>) where T: Display + std::fmt::Debug{ // 1. Loop over each item in the vector and print it using `println!` for item in data.iter(){ println!("{}", item) }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc_items = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&rc_items)) } }// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T: std::fmt::Display>(data: Rc<Vec<T>>){ // 1. Loop over each item in the vector and print it using `println!` data.iter().for_each(|v| println!("{}", v));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let a = Rc::new(items); take_item(Rc::clone(&a)); take_item(Rc::clone(&a)); take_item(Rc::clone(&a));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T : std::fmt::Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` data.iter().for_each(|value| println!("{}" , value));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let reference = Rc::new(items); take_item(Rc::clone(&reference)); take_item(Rc::clone(&reference)); take_item(Rc::clone(&reference));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T: std::fmt::Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` data.iter().for_each(|d| println!("{}", d));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let cloned = Rc::new(items); take_item(Rc::clone(&cloned)); take_item(Rc::clone(&cloned)); take_item(Rc::clone(&cloned));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use core::fmt::Display;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for d in data.iter() { println!("{}", d); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared_items = Rc::new(items); take_item(Rc::clone(&shared_items)); take_item(Rc::clone(&shared_items)); take_item(Rc::clone(&shared_items));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T: std::fmt::Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let shared = Rc::new(items); // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure take_item(Rc::clone(&shared)); take_item(Rc::clone(&shared)); take_item(Rc::clone(&shared));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc = Rc::new(items); take_item(rc.clone()); take_item(rc.clone()); take_item(rc.clone());}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ // 1. Loop over each item in the vector and print it using `println!` data.iter().for_each(|item| println!("{}", item));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc_items = Rc::new(items); for _ in 0..=2 { take_item(Rc::clone(&rc_items)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: std::fmt::Display,{ for item in data.iter() { println!("{}", item) }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let rc_items = Rc::new(items); take_item(Rc::clone(&rc_items)); take_item(Rc::clone(&rc_items)); take_item(Rc::clone(&rc_items));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ // 1. Loop over each item in the vector and print it using `println!` for d in (*data).iter() { println!("{d}"); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let ref_count = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&ref_count)) }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T: std::fmt::Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&shared)) } }// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display{ // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{item}"); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&rc)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ // 1. Loop over each item in the vector and print it using `println!` data.iter().for_each(|q| println!("{}", q));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared = Rc::new(items); take_item(Rc::clone(&shared)); take_item(Rc::clone(&shared)); take_item(Rc::clone(&shared));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ for each in data.as_ref() { println!("{}", each) }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let ref_data = Rc::new(items); take_item(Rc::clone(&ref_data)); take_item(Rc::clone(&ref_data)); take_item(Rc::clone(&ref_data));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { data .iter() .for_each(|x| println!("{x}"));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let ref_count = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&ref_count)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` data .iter() .for_each(|x| println!("{x}"));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let ref_count = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&ref_count)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { data.iter().for_each(|x| println!("{}", x));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // Share the data as a reference-counted pointer 3 times with the closure let rc = Rc::new(items); for _ in 0..3 { take_item(rc.clone()); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: 'static + Send + Sync + Display,{ // 1. Implement the function // Loop over each item in the vector and print it using `println!` for element in data.iter() { println!("{}", *element); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let data = Rc::new(items); take_item(Rc::clone(&data)); take_item(Rc::clone(&data)); take_item(Rc::clone(&data));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { data.iter().for_each(|x| println!("{x}"));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc = Rc::new(items); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{item}") }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let ref_count = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&ref_count)) }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { for d in data.iter() { println!("{}", d) } // 1. Loop over each item in the vector and print it using `println!`}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared_items = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&shared_items)) }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;use std::fmt::Debug;pub fn use_shared_data<T: Display+Debug>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item) }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let rc = Rc::new(items); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for row in data.iter() { println!("{}", row); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let n = Rc::new(items); take_item(Rc::clone(&n)); take_item(Rc::clone(&n)); take_item(Rc::clone(&n));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared_data = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&shared_data)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared_data = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&shared_data)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T:std::fmt::Display>(data: Rc<Vec<T>>) { for element in &*data { println!("{}", element); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let rc_a = Rc::new(items); take_item(Rc::clone(&rc_a)); take_item(Rc::clone(&rc_a)); take_item(Rc::clone(&rc_a)); }// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let rc = Rc::new(items); take_item(rc.clone()); take_item(rc.clone()); take_item(rc.clone());}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T>(data: Rc<Vec<T>>) where T:Display { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter(){ println!("{}",item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let shared_items = Rc::new(items); take_item(Rc::clone(&shared_items)); take_item(Rc::clone(&shared_items)); take_item(Rc::clone(&shared_items));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display{ data.iter().for_each(|item| { println!("{}", item); })}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let shared_items = Rc::new(items); take_item(Rc::clone(&shared_items)); take_item(Rc::clone(&shared_items)); take_item(Rc::clone(&shared_items)); // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::fmt::Display;use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let items = Rc::new(items); take_item(Rc::clone(&items)); take_item(Rc::clone(&items)); take_item(Rc::clone(&items));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T: std::fmt::Display>(data: Rc<Vec<T>>) { let l = data.len(); for i in 0..l { let x = data.get(i).unwrap(); println!("{x}"); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let data = Rc::new(items); take_item(Rc::clone(&data)); take_item(Rc::clone(&data)); take_item(Rc::clone(&data));}use std::{ rc::Rc, fmt::Display};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for i in &*data { println!("{i}") }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let items = Rc::new(items); for _ in 0..3 { take_item(Rc::clone(&items)) }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: std::fmt::Display,{ // 1. Loop over each item in the vector and print it using `println!` for e in data.iter() { println!("{}", e); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let temp = Rc::new(items); take_item(Rc::clone(&temp)); take_item(Rc::clone(&temp)); take_item(Rc::clone(&temp));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>) where T: std::fmt::Display,{ // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let data: Rc<Vec<String>> = Rc::from(items); take_item(data.clone()); take_item(data.clone()); take_item(data.clone());}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ data.as_ref().iter().for_each(|item| { println!("{item}"); });}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let items = Rc::new(items); take_item(Rc::clone(&items)); take_item(Rc::clone(&items)); take_item(Rc::clone(&items));}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let rc = Rc::new(items); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc)); take_item(Rc::clone(&rc));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: std::fmt::Display{ // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let items = Rc::new(items); for _i in 0..3 { take_item(Rc::clone(&items)); }}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for i in data.iter() { println!("{}", i) }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let t = Rc::new(items); take_item(Rc::clone(&t)); take_item(Rc::clone(&t)); take_item(Rc::clone(&t)); // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;use std::fmt::Display;pub fn use_shared_data<T: Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for i in data.iter() { println!("{}", i) }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let t = Rc::new(items); take_item(Rc::clone(&t)); take_item(Rc::clone(&t)); take_item(Rc::clone(&t)); // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::{fmt::Display, rc::Rc};pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: Display,{ data.iter().for_each(|p| println!("{}", p));}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let shared = Rc::new(items); take_item(Rc::clone(&shared)); take_item(Rc::clone(&shared)); take_item(Rc::clone(&shared));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T:std::fmt::Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for each_data in data.iter(){ println!("{}",each_data); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let data = Rc::new(items); take_item(Rc::clone(&data)); take_item(Rc::clone(&data)); take_item(Rc::clone(&data));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T: std::fmt::Display>(data: Rc<Vec<T>>) { // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!("{}", item); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let r = Rc::new(items); take_item(Rc::clone(&r)); take_item(Rc::clone(&r)); take_item(Rc::clone(&r));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: std::fmt::Display,{ // 1. Loop over each item in the vector and print it using `println!` for item in data.iter() { println!{"{}", item}; }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure let reference = Rc::new(items); take_item(Rc::clone(&reference)); take_item(Rc::clone(&reference)); take_item(Rc::clone(&reference));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>) // 1. Loop over each item in the vector and print it using `println!` where T: std::fmt::Display, { for data in data.iter() { println!("{}", data); } }pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>), { let rc_items = Rc::new(items); take_item(Rc::clone(&rc_items)); take_item(Rc::clone(&rc_items)); take_item(Rc::clone(&rc_items)); // 2. Implement the function // Share the data as a reference-counted pointer 3 times with the closure}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}use std::rc::Rc;pub fn use_shared_data<T>(data: Rc<Vec<T>>)where T: std::fmt::Display,{ for data in data.iter() { println!("{}", data); }}pub fn share_data_to_other_functions<F>(mut take_item: F, items: Vec<String>)where F: FnMut(Rc<Vec<String>>),{ let rc_items = Rc::new(items); take_item(Rc::clone(&rc_items)); take_item(Rc::clone(&rc_items)); take_item(Rc::clone(&rc_items));}// Example usagepub fn main() { // Example usage of `use_shared_data` let shared_numbers = Rc::new(vec![1, 2, 3, 4, 5]); println!("Using shared data:"); use_shared_data(Rc::clone(&shared_numbers)); // Example usage of `share_data_to_other_functions` let strings = vec!["Rust".to_string(), "is".to_string(), "awesome!".to_string()]; let print_data = |data: Rc<Vec<String>>| { println!("Printing shared data:"); for item in data.iter() { println!("{}", item); } }; println!("\nSharing data with other functions:"); share_data_to_other_functions(print_data, strings);}