I have the following code,
impl<T: Debug + Into<String> + Clone> TryFrom<Vec<T>> for Positionals {
type Error = &'static str;
fn try_from(mut vec: Vec<T>) -> Result<Self, Self::Error> {
let mystr: String = vec.get(0).unwrap().into();
And that code is producing this error,
error[E0277]: the trait bound `String: From<&T>` is not satisfied
--> bin/seq.rs:21:43
|
21 | let mystr: String = vec.get(0).unwrap().into();
| ^^^^ the trait `From<&T>` is not implemented for `String`
|
= note: required because of the requirements on the impl of `Into<String>` for `&T`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
I'm confused as to why this is generating an error because I have a trait bound on Vec<T> such that T must implement Into<String>, what else is required? I don't understand why this is, I remove the into(), I get
let mystr: String = vec.get(0).unwrap();
------ ^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&T`
How can I get my T in Vec<T> to String? The reason why I'm doing Vec<T> and not Vec<String> is because I want to support Vec<&str> too.