I want to convert the &[T] into a big string using .join method but I am getting these issues.
the method join exists for reference &[T], but its trait bounds were not satisfied
method cannot be called on &[T] due to unsatisfied trait bounds
note: the following trait bounds were not satisfied: [T]: std::slice::Join<_>rustc(E0599)
main.rs(157, 42): method cannot be called on &[T] due to unsatisfied trait bounds
the method join exists for reference &[T], but its trait bounds were not satisfied the following trait bounds were not satisfied: [T]: Join<_>rustcE0599
I am new to rust and not able to figure out what is going wrong... Can anyone please help me to convert the slice into string?
What are you expecting to get from _first_list.join(" ")? The only thing you know about T is that you can compare it with itself, but join will have to somehow build a string - how?
If you want to be able to print for any arbitrary T, it must have a trait bound which allows it to be convertible to a string. Two common such traits are Debug and Display. For numbers, you can use either - in general if you want to print something Display makes more sense, while Debug is as the name suggests more for debug output.
So, in your case, you need a trait bound of T: PartialEq + Display. Then you can do something like:
let first_list_str = first_list.into_iter().cloned().map(Display::to_string).collect::<Vec<_>>();
let first = first_list_str.join(" ");
println!("{}", first);